From b3b84695aaa336ed6c4cea208020cf44613e052d Mon Sep 17 00:00:00 2001 From: JoshuaReason Date: Thu, 3 Oct 2019 15:47:09 +1000 Subject: [PATCH] fixed gizmos breaking things on play --- Assets/Scripts/LevelBlocks/Block.cs | 12 ++--- Assets/Scripts/Utility/DebugExtensions.cs | 56 +++++++++++++---------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/Assets/Scripts/LevelBlocks/Block.cs b/Assets/Scripts/LevelBlocks/Block.cs index dbf49b1..a691104 100644 --- a/Assets/Scripts/LevelBlocks/Block.cs +++ b/Assets/Scripts/LevelBlocks/Block.cs @@ -170,7 +170,7 @@ public class Block : MonoBehaviour #if UNITY_EDITOR offset = Vector3.up * Mathf.Sin((float)UnityEditor.EditorApplication.timeSinceStartup * 0.5f) * 0.1f; #endif - DebugExtensions.DrawCube(DrawPosition + offset, 0.15f, Color.yellow, 0); + DebugExtensions.DrawCube(DrawPosition + offset, 0.15f, Color.yellow, 0,true); #if UNITY_EDITOR var view = UnityEditor.EditorWindow.GetWindow(); @@ -185,18 +185,18 @@ public class Block : MonoBehaviour 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 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 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); - 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); diff --git a/Assets/Scripts/Utility/DebugExtensions.cs b/Assets/Scripts/Utility/DebugExtensions.cs index fb8111e..7c0636f 100644 --- a/Assets/Scripts/Utility/DebugExtensions.cs +++ b/Assets/Scripts/Utility/DebugExtensions.cs @@ -7,7 +7,7 @@ using UnityEngine; /// public static class DebugExtensions { - + /// /// Draws wireframe cube in scene view /// @@ -16,34 +16,40 @@ public static class DebugExtensions /// Color of lines /// Amount of time cube is displayed /// Should cube be obsured by otherobjects - 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 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 - // 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); } /// @@ -53,10 +59,10 @@ public static class DebugExtensions /// extent of cube (half of size) /// Color of lines /// Amount of time cube is displayed - 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 - 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); } - + }//End DebugExtentions