You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
4.7 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// Static class for adding More Debug funtions
  6. /// </summary>
  7. public static class DebugExtensions
  8. {
  9. /// <summary>
  10. /// Draws wireframe cube in scene view
  11. /// </summary>
  12. /// <param name="Position">Centre of cube</param>
  13. /// <param name="Extent">extent of cube (half of size)</param>
  14. /// <param name="color">Color of lines</param>
  15. /// <param name="duration">Amount of time cube is displayed</param>
  16. /// <param name="depthTest">Should cube be obsured by otherobjects</param>
  17. public static void DrawCube(Vector3 Position, Vector3 Extent, Color color, float duration, bool depthTest = true)
  18. {
  19. Vector3 min = Position - Extent;
  20. Vector3 max = Position + Extent;
  21. Color oldColor = Gizmos.color;
  22. Gizmos.color = color;
  23. Gizmos.DrawWireCube(Position, Extent * 2);
  24. Gizmos.color = oldColor;
  25. //Draw bottom Square
  26. // Debug.DrawLine(new Vector3(min.x, min.y, min.z), new Vector3(min.x, min.y, max.z), color, duration, depthTest);
  27. // Debug.DrawLine(new Vector3(min.x, min.y, max.z), new Vector3(max.x, min.y, max.z), color, duration, depthTest);
  28. // Debug.DrawLine(new Vector3(max.x, min.y, max.z), new Vector3(max.x, min.y, min.z), color, duration, depthTest);
  29. // Debug.DrawLine(new Vector3(max.x, min.y, min.z), new Vector3(min.x, min.y, min.z), color, duration, depthTest);
  30. //
  31. // //top square
  32. // Debug.DrawLine(new Vector3(min.x, max.y, min.z), new Vector3(min.x, max.y, max.z), color, duration, depthTest);
  33. // Debug.DrawLine(new Vector3(min.x, max.y, max.z), new Vector3(max.x, max.y, max.z), color, duration, depthTest);
  34. // Debug.DrawLine(new Vector3(max.x, max.y, max.z), new Vector3(max.x, max.y, min.z), color, duration, depthTest);
  35. // Debug.DrawLine(new Vector3(max.x, max.y, min.z), new Vector3(min.x, max.y, min.z), color, duration, depthTest);
  36. //
  37. // //connect top and bottom
  38. // Debug.DrawLine(new Vector3(min.x, min.y, min.z), new Vector3(min.x, max.y, min.z), color, duration, depthTest);
  39. // Debug.DrawLine(new Vector3(min.x, min.y, max.z), new Vector3(min.x, max.y, max.z), color, duration, depthTest);
  40. // Debug.DrawLine(new Vector3(max.x, min.y, max.z), new Vector3(max.x, max.y, max.z), color, duration, depthTest);
  41. // Debug.DrawLine(new Vector3(max.x, min.y, min.z), new Vector3(max.x, max.y, min.z), color, duration, depthTest);
  42. }
  43. /// <summary>
  44. /// Draws wireframe cube in scene view
  45. /// </summary>
  46. /// <param name="Position">Centre of cube</param>
  47. /// <param name="Extent">extent of cube (half of size)</param>
  48. /// <param name="color">Color of lines</param>
  49. /// <param name="duration">Amount of time cube is displayed</param>
  50. public static void DrawCube(Vector3 Position, float Extent, Color color, float duration)
  51. {
  52. //Call overload funtion
  53. DrawCube(Position, Vector3.one * Extent, color, duration);
  54. }
  55. /// <summary>
  56. /// Draws wireframe around a RectTransform in scene view
  57. /// </summary>
  58. /// <param name="rect">Rect to draw around</param>
  59. /// <param name="color">Color of the lines</param>
  60. /// <param name="duration">How long the lines should be visible for</param>
  61. /// <param name="depthTest">Should the lines be obscured by objects closer to the camera</param>
  62. public static void DrawRect(Rect rect, Color color, float duration = 0.0f, bool depthTest = false)
  63. {
  64. Debug.DrawLine(new Vector3(rect.min.x, rect.max.y, 0), new Vector3(rect.max.x, rect.max.y, 0), color, duration, depthTest);
  65. Debug.DrawLine(new Vector3(rect.max.x, rect.max.y, 0), new Vector3(rect.max.x, rect.min.y, 0), color, duration, depthTest);
  66. Debug.DrawLine(new Vector3(rect.max.x, rect.min.y, 0), new Vector3(rect.min.x, rect.min.y, 0), color, duration, depthTest);
  67. Debug.DrawLine(new Vector3(rect.min.x, rect.min.y, 0), new Vector3(rect.min.x, rect.max.y, 0), color, duration, depthTest);
  68. }
  69. /// <summary>
  70. /// Draws wireframe around a RectTransform in scene view
  71. /// </summary>
  72. /// <param name="transform">Rect transform to draw around</param>
  73. /// <param name="color">Color of the lines</param>
  74. /// <param name="duration">How long the lines should be visible for</param>
  75. /// <param name="depthTest">Should the lines be obscured by objects closer to the camera</param>
  76. public static void DrawRect(RectTransform transform, Color color, float duration = 0.0f, bool depthTest = false)
  77. {
  78. Rect rect = transform.GlobalRect();
  79. DrawRect(rect, color, duration, depthTest);
  80. }
  81. }//End DebugExtentions