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.

142 lines
6.8 KiB

3 years ago
  1. using System.ComponentModel;
  2. using UnityEngine;
  3. namespace DebugDrawEx
  4. {
  5. public static class DebugDraw
  6. {
  7. /// <summary>
  8. /// <para>Draws a line between specified start and end points.</para>
  9. /// </summary>
  10. /// <param name="start">Point in world space where the line should start.</param>
  11. /// <param name="end">Point in world space where the line should end.</param>
  12. /// <param name="color">Color of the line.</param>
  13. /// <param name="duration">How long the line should be visible for.</param>
  14. /// <param name="depthTest">Should the line be obscured by objects closer to the camera?</param>
  15. public static void DrawLine(Vector3 start, Vector3 end)
  16. {
  17. bool depthTest = true;
  18. float duration = 0.0f;
  19. Color white = Color.white;
  20. DrawLine(start, end, white, duration, depthTest);
  21. }
  22. /// <summary>
  23. /// <para>Draws a line between specified start and end points.</para>
  24. /// </summary>
  25. /// <param name="start">Point in world space where the line should start.</param>
  26. /// <param name="end">Point in world space where the line should end.</param>
  27. /// <param name="color">Color of the line.</param>
  28. /// <param name="duration">How long the line should be visible for.</param>
  29. /// <param name="depthTest">Should the line be obscured by objects closer to the camera?</param>
  30. public static void DrawLine(Vector3 start, Vector3 end, Color color)
  31. {
  32. bool depthTest = true;
  33. float duration = 0.0f;
  34. DrawLine(start, end, color, duration, depthTest);
  35. }
  36. /// <summary>
  37. /// <para>Draws a line between specified start and end points.</para>
  38. /// </summary>
  39. /// <param name="start">Point in world space where the line should start.</param>
  40. /// <param name="end">Point in world space where the line should end.</param>
  41. /// <param name="color">Color of the line.</param>
  42. /// <param name="duration">How long the line should be visible for.</param>
  43. /// <param name="depthTest">Should the line be obscured by objects closer to the camera?</param>
  44. public static void DrawLine(Vector3 start, Vector3 end, Color color, float duration)
  45. {
  46. bool depthTest = true;
  47. DrawLine(start, end, color, duration, depthTest);
  48. }
  49. /// <summary>
  50. /// <para>Draws a line between specified start and end points.</para>
  51. /// </summary>
  52. /// <param name="start">Point in world space where the line should start.</param>
  53. /// <param name="end">Point in world space where the line should end.</param>
  54. /// <param name="color">Color of the line.</param>
  55. /// <param name="duration">How long the line should be visible for.</param>
  56. /// <param name="depthTest">Should the line be obscured by objects closer to the camera?</param>
  57. public static void DrawLine(
  58. Vector3 start,
  59. Vector3 end,
  60. [DefaultValue("Color.white")] Color color,
  61. [DefaultValue("0.0f")] float duration,
  62. [DefaultValue("true")] bool depthTest)
  63. {
  64. var line = new Line
  65. {
  66. Duration = duration,
  67. DepthTest = depthTest
  68. };
  69. line.AddLine(start, end, color);
  70. Graphics.DrawMesh(line.Mesh, Vector3.zero, Quaternion.identity, line.Mat,
  71. 0 , null, 0, null, false,false);
  72. }
  73. /// <summary>
  74. /// <para>Draws a line from start to start + dir in world coordinates.</para>
  75. /// </summary>
  76. /// <param name="start">Point in world space where the ray should start.</param>
  77. /// <param name="dir">Direction and length of the ray.</param>
  78. /// <param name="color">Color of the drawn line.</param>
  79. /// <param name="duration">How long the line will be visible for (in seconds).</param>
  80. /// <param name="depthTest">Should the line be obscured by other objects closer to the camera?</param>
  81. public static void DrawRay(Vector3 start, Vector3 dir)
  82. {
  83. bool depthTest = true;
  84. float duration = 0.0f;
  85. Color white = Color.white;
  86. DrawRay(start, dir, white, duration, depthTest);
  87. }
  88. /// <summary>
  89. /// <para>Draws a line from start to start + dir in world coordinates.</para>
  90. /// </summary>
  91. /// <param name="start">Point in world space where the ray should start.</param>
  92. /// <param name="dir">Direction and length of the ray.</param>
  93. /// <param name="color">Color of the drawn line.</param>
  94. /// <param name="duration">How long the line will be visible for (in seconds).</param>
  95. /// <param name="depthTest">Should the line be obscured by other objects closer to the camera?</param>
  96. public static void DrawRay(Vector3 start, Vector3 dir, Color color)
  97. {
  98. bool depthTest = true;
  99. float duration = 0.0f;
  100. DrawRay(start, dir, color, duration, depthTest);
  101. }
  102. /// <summary>
  103. /// <para>Draws a line from start to start + dir in world coordinates.</para>
  104. /// </summary>
  105. /// <param name="start">Point in world space where the ray should start.</param>
  106. /// <param name="dir">Direction and length of the ray.</param>
  107. /// <param name="color">Color of the drawn line.</param>
  108. /// <param name="duration">How long the line will be visible for (in seconds).</param>
  109. /// <param name="depthTest">Should the line be obscured by other objects closer to the camera?</param>
  110. public static void DrawRay(Vector3 start, Vector3 dir, Color color, float duration)
  111. {
  112. bool depthTest = true;
  113. DrawRay(start, dir, color, duration, depthTest);
  114. }
  115. /// <summary>
  116. /// <para>Draws a line from start to start + dir in world coordinates.</para>
  117. /// </summary>
  118. /// <param name="start">Point in world space where the ray should start.</param>
  119. /// <param name="dir">Direction and length of the ray.</param>
  120. /// <param name="color">Color of the drawn line.</param>
  121. /// <param name="duration">How long the line will be visible for (in seconds).</param>
  122. /// <param name="depthTest">Should the line be obscured by other objects closer to the camera?</param>
  123. public static void DrawRay(
  124. Vector3 start,
  125. Vector3 dir,
  126. [DefaultValue("Color.white")] Color color,
  127. [DefaultValue("0.0f")] float duration,
  128. [DefaultValue("true")] bool depthTest)
  129. {
  130. DrawLine(start, start + dir, color, duration, depthTest);
  131. }
  132. }
  133. }