Browse Source

fixed gizmos breaking things on play

master
JoshuaReason 5 years ago
parent
commit
b3b84695aa
2 changed files with 37 additions and 31 deletions
  1. +6
    -6
      Assets/Scripts/LevelBlocks/Block.cs
  2. +31
    -25
      Assets/Scripts/Utility/DebugExtensions.cs

+ 6
- 6
Assets/Scripts/LevelBlocks/Block.cs View File

@ -170,7 +170,7 @@ public class Block : MonoBehaviour
#if UNITY_EDITOR #if UNITY_EDITOR
offset = Vector3.up * Mathf.Sin((float)UnityEditor.EditorApplication.timeSinceStartup * 0.5f) * 0.1f; offset = Vector3.up * Mathf.Sin((float)UnityEditor.EditorApplication.timeSinceStartup * 0.5f) * 0.1f;
#endif #endif
DebugExtensions.DrawCube(DrawPosition + offset, 0.15f, Color.yellow, 0);
DebugExtensions.DrawCube(DrawPosition + offset, 0.15f, Color.yellow, 0,true);
#if UNITY_EDITOR #if UNITY_EDITOR
var view = UnityEditor.EditorWindow.GetWindow<UnityEditor.SceneView>(); var view = UnityEditor.EditorWindow.GetWindow<UnityEditor.SceneView>();
@ -185,18 +185,18 @@ public class Block : MonoBehaviour
Vector3 Perp = Quaternion.Euler(0, 90, 0) * SpawnDirection.ToVector(); Vector3 Perp = Quaternion.Euler(0, 90, 0) * SpawnDirection.ToVector();
DebugExtensions.DrawCube(DrawPosition, 0.4f, Color.magenta, 0);
DebugExtensions.DrawCube(DrawPosition, 0.4f, Color.magenta, 0, true);
//Eyes //Eyes
Vector3 eyePosition = DrawPosition + SpawnDirection.ToVector() * 0.4f; Vector3 eyePosition = DrawPosition + SpawnDirection.ToVector() * 0.4f;
DebugExtensions.DrawCube(eyePosition + Perp * 0.2f, 0.1f, Color.magenta, 0);
DebugExtensions.DrawCube(eyePosition - Perp * 0.2f, 0.1f, Color.magenta, 0);
DebugExtensions.DrawCube(eyePosition + Perp * 0.2f, 0.1f, Color.magenta, 0, true);
DebugExtensions.DrawCube(eyePosition - Perp * 0.2f, 0.1f, Color.magenta, 0, true);
//ears //ears
Vector3 earPosition = DrawPosition + SpawnDirection.ToVector() * 0.2f + Vector3.up * 0.4f; Vector3 earPosition = DrawPosition + SpawnDirection.ToVector() * 0.2f + Vector3.up * 0.4f;
Vector3 earScale = Quaternion.LookRotation(SpawnDirection.ToVector()) * new Vector3(0.1f, 0.1f, 0.05f); Vector3 earScale = Quaternion.LookRotation(SpawnDirection.ToVector()) * new Vector3(0.1f, 0.1f, 0.05f);
DebugExtensions.DrawCube(earPosition + Perp * 0.3f, earScale, Color.magenta, 0);
DebugExtensions.DrawCube(earPosition - Perp * 0.3f, earScale, Color.magenta, 0);
DebugExtensions.DrawCube(earPosition + Perp * 0.3f, earScale, Color.magenta, 0, true);
DebugExtensions.DrawCube(earPosition - Perp * 0.3f, earScale, Color.magenta, 0, true);

+ 31
- 25
Assets/Scripts/Utility/DebugExtensions.cs View File

@ -7,7 +7,7 @@ using UnityEngine;
/// </summary> /// </summary>
public static class DebugExtensions public static class DebugExtensions
{ {
/// <summary> /// <summary>
/// Draws wireframe cube in scene view /// Draws wireframe cube in scene view
/// </summary> /// </summary>
@ -16,34 +16,40 @@ public static class DebugExtensions
/// <param name="color">Color of lines</param> /// <param name="color">Color of lines</param>
/// <param name="duration">Amount of time cube is displayed</param> /// <param name="duration">Amount of time cube is displayed</param>
/// <param name="depthTest">Should cube be obsured by otherobjects</param> /// <param name="depthTest">Should cube be obsured by otherobjects</param>
public static void DrawCube(Vector3 Position, Vector3 Extent, Color color, float duration, bool depthTest = true)
public static void DrawCube(Vector3 Position, Vector3 Extent, Color color, float duration, bool depthTest = true, bool isGizmo = false)
{ {
Vector3 min = Position - Extent; Vector3 min = Position - Extent;
Vector3 max = Position + Extent; Vector3 max = Position + Extent;
Color oldColor = Gizmos.color;
Gizmos.color = color;
Gizmos.DrawWireCube(Position, Extent * 2);
Gizmos.color = oldColor;
if (isGizmo)
{
Color oldColor = Gizmos.color;
Gizmos.color = color;
Gizmos.DrawWireCube(Position, Extent * 2);
Gizmos.color = oldColor;
return;
}
//Draw bottom Square //Draw bottom Square
// Debug.DrawLine(new Vector3(min.x, min.y, min.z), new Vector3(min.x, min.y, max.z), color, duration, depthTest);
// Debug.DrawLine(new Vector3(min.x, min.y, max.z), new Vector3(max.x, min.y, max.z), color, duration, depthTest);
// Debug.DrawLine(new Vector3(max.x, min.y, max.z), new Vector3(max.x, min.y, min.z), color, duration, depthTest);
// Debug.DrawLine(new Vector3(max.x, min.y, min.z), new Vector3(min.x, min.y, min.z), color, duration, depthTest);
//
// //top square
// Debug.DrawLine(new Vector3(min.x, max.y, min.z), new Vector3(min.x, max.y, max.z), color, duration, depthTest);
// Debug.DrawLine(new Vector3(min.x, max.y, max.z), new Vector3(max.x, max.y, max.z), color, duration, depthTest);
// Debug.DrawLine(new Vector3(max.x, max.y, max.z), new Vector3(max.x, max.y, min.z), color, duration, depthTest);
// Debug.DrawLine(new Vector3(max.x, max.y, min.z), new Vector3(min.x, max.y, min.z), color, duration, depthTest);
//
// //connect top and bottom
// Debug.DrawLine(new Vector3(min.x, min.y, min.z), new Vector3(min.x, max.y, min.z), color, duration, depthTest);
// Debug.DrawLine(new Vector3(min.x, min.y, max.z), new Vector3(min.x, max.y, max.z), color, duration, depthTest);
// Debug.DrawLine(new Vector3(max.x, min.y, max.z), new Vector3(max.x, max.y, max.z), color, duration, depthTest);
// Debug.DrawLine(new Vector3(max.x, min.y, min.z), new Vector3(max.x, max.y, min.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(min.x, min.y, min.z), new Vector3(min.x, min.y, max.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(min.x, min.y, max.z), new Vector3(max.x, min.y, max.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(max.x, min.y, max.z), new Vector3(max.x, min.y, min.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(max.x, min.y, min.z), new Vector3(min.x, min.y, min.z), color, duration, depthTest);
//top square
Debug.DrawLine(new Vector3(min.x, max.y, min.z), new Vector3(min.x, max.y, max.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(min.x, max.y, max.z), new Vector3(max.x, max.y, max.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(max.x, max.y, max.z), new Vector3(max.x, max.y, min.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(max.x, max.y, min.z), new Vector3(min.x, max.y, min.z), color, duration, depthTest);
//connect top and bottom
Debug.DrawLine(new Vector3(min.x, min.y, min.z), new Vector3(min.x, max.y, min.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(min.x, min.y, max.z), new Vector3(min.x, max.y, max.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(max.x, min.y, max.z), new Vector3(max.x, max.y, max.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(max.x, min.y, min.z), new Vector3(max.x, max.y, min.z), color, duration, depthTest);
} }
/// <summary> /// <summary>
@ -53,10 +59,10 @@ public static class DebugExtensions
/// <param name="Extent">extent of cube (half of size)</param> /// <param name="Extent">extent of cube (half of size)</param>
/// <param name="color">Color of lines</param> /// <param name="color">Color of lines</param>
/// <param name="duration">Amount of time cube is displayed</param> /// <param name="duration">Amount of time cube is displayed</param>
public static void DrawCube(Vector3 Position, float Extent, Color color, float duration)
public static void DrawCube(Vector3 Position, float Extent, Color color, float duration, bool isGizmo = false)
{ {
//Call overload funtion //Call overload funtion
DrawCube(Position, Vector3.one * Extent, color, duration);
DrawCube(Position, Vector3.one * Extent, color, duration,false);
} }
@ -89,7 +95,7 @@ public static class DebugExtensions
DrawRect(rect, color, duration, depthTest); DrawRect(rect, color, duration, depthTest);
} }
}//End DebugExtentions }//End DebugExtentions

Loading…
Cancel
Save