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.

75 lines
3.9 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. //Draw bottom Square
  22. Debug.DrawLine(new Vector3(min.x, min.y, min.z), new Vector3(min.x, min.y, max.z), color, duration, depthTest);
  23. Debug.DrawLine(new Vector3(min.x, min.y, max.z), new Vector3(max.x, min.y, max.z), color, duration, depthTest);
  24. Debug.DrawLine(new Vector3(max.x, min.y, max.z), new Vector3(max.x, min.y, min.z), color, duration, depthTest);
  25. Debug.DrawLine(new Vector3(max.x, min.y, min.z), new Vector3(min.x, min.y, min.z), color, duration, depthTest);
  26. //top square
  27. Debug.DrawLine(new Vector3(min.x, max.y, min.z), new Vector3(min.x, max.y, max.z), color, duration, depthTest);
  28. Debug.DrawLine(new Vector3(min.x, max.y, max.z), new Vector3(max.x, max.y, max.z), color, duration, depthTest);
  29. Debug.DrawLine(new Vector3(max.x, max.y, max.z), new Vector3(max.x, max.y, min.z), color, duration, depthTest);
  30. Debug.DrawLine(new Vector3(max.x, max.y, min.z), new Vector3(min.x, max.y, min.z), color, duration, depthTest);
  31. //connect top and bottom
  32. Debug.DrawLine(new Vector3(min.x, min.y, min.z), new Vector3(min.x, max.y, min.z), color, duration, depthTest);
  33. Debug.DrawLine(new Vector3(min.x, min.y, max.z), new Vector3(min.x, max.y, max.z), color, duration, depthTest);
  34. Debug.DrawLine(new Vector3(max.x, min.y, max.z), new Vector3(max.x, max.y, max.z), color, duration, depthTest);
  35. Debug.DrawLine(new Vector3(max.x, min.y, min.z), new Vector3(max.x, max.y, min.z), color, duration, depthTest);
  36. }
  37. /// <summary>
  38. /// Draws wireframe cube in scene view
  39. /// </summary>
  40. /// <param name="Position">Centre of cube</param>
  41. /// <param name="Extent">extent of cube (half of size)</param>
  42. /// <param name="color">Color of lines</param>
  43. /// <param name="duration">Amount of time cube is displayed</param>
  44. public static void DrawCube(Vector3 Position, float Extent, Color color, float duration)
  45. {
  46. //Call overload funtion
  47. DrawCube(Position, Vector3.one * Extent, color, duration);
  48. }
  49. /// <summary>
  50. /// Draws wireframe around a RectTransform in scene view
  51. /// </summary>
  52. /// <param name="transform">Rect transform to draw around</param>
  53. /// <param name="color">Color of the lines</param>
  54. /// <param name="duration">How long the lines should be visible for</param>
  55. /// <param name="depthTest">Should the lines be obscured by objects closer to the camera</param>
  56. public static void DrawRect(RectTransform transform, Color color, float duration = 0.0f, bool depthTest = false)
  57. {
  58. Rect rect = transform.GlobalRect();
  59. Debug.DrawLine(new Vector3(rect.min.x, rect.max.y, 0), new Vector3(rect.max.x, rect.max.y, 0), color, duration, depthTest);
  60. Debug.DrawLine(new Vector3(rect.max.x, rect.max.y, 0), new Vector3(rect.max.x, rect.min.y, 0), color, duration, depthTest);
  61. Debug.DrawLine(new Vector3(rect.max.x, rect.min.y, 0), new Vector3(rect.min.x, rect.min.y, 0), color, duration, depthTest);
  62. Debug.DrawLine(new Vector3(rect.min.x, rect.min.y, 0), new Vector3(rect.min.x, rect.max.y, 0), color, duration, depthTest);
  63. }
  64. }//End DebugExtentions