/// <summary>- Debugs a cone.</summary> /// <param name='position'>- The position for the tip of the cone.</param> /// <param name='direction'>- The direction for the cone gets wider in.</param> /// <param name='angle'>- The angle of the cone.</param> /// <param name='color'>- The color of the cone.</param> /// <param name='duration'>- How long to draw the cone.</param> /// <param name='depthTest'>- Whether or not the cone should be faded when behind other objects.</param> public static void DrawCone(Vector3 position, Vector3 direction, Color color = default(Color), float angle = 45f, float duration = 0, bool depthTest = false) { float length = direction.magnitude; direction = direction.normalized; Vector3 forward = direction, up = Vector3.Slerp(forward, -forward, 0.5f), right = Vector3.Cross(forward, up).normalized *length, slerpedVector = Vector3.Slerp(forward, up, angle / 90.0f); Plane farPlane = new Plane(-direction, position + forward); Ray distRay = new Ray(position, slerpedVector); float dist; farPlane.Raycast(distRay, out dist); color = (color == default(Color)) ? Color.white : color; Debug.DrawRay(position, slerpedVector.normalized * dist, color); Debug.DrawRay(position, Vector3.Slerp(forward, -up, angle / 90.0f).normalized *dist, color, duration, depthTest); Debug.DrawRay(position, Vector3.Slerp(forward, right, angle / 90.0f).normalized *dist, color, duration, depthTest); Debug.DrawRay(position, Vector3.Slerp(forward, -right, angle / 90.0f).normalized *dist, color, duration, depthTest); DebugExtend.DrawCircle(position + forward, direction, color, (forward - (slerpedVector.normalized * dist)).magnitude, duration, depthTest); DebugExtend.DrawCircle(position + (forward * 0.5f), direction, color, ((forward * 0.5f) - (slerpedVector.normalized * (dist * 0.5f))).magnitude, duration, depthTest); }
/// <summary>- Debugs a cylinder.</summary> /// <param name='start'>- The position of one end of the cylinder.</param> /// <param name='end'>- The position of the other end of the cylinder.</param> /// <param name='color'>- The color of the cylinder.</param> /// <param name='radius'>- The radius of the cylinder.</param> /// <param name='duration'>- How long to draw the cylinder.</param> /// <param name='depthTest'>- Whether or not the cylinder should be faded when behind other objects.</param> public static void DrawCylinder(Vector3 start, Vector3 end, Color color = default(Color), float radius = 1, float duration = 0, bool depthTest = false) { Vector3 up = (end - start).normalized * radius, forward = Vector3.Slerp(up, -up, 0.5f), right = Vector3.Cross(up, forward).normalized *radius; color = (color == default(Color)) ? Color.white : color; //Radial circles DebugExtend.DrawCircle(start, up, color, radius, duration, depthTest); DebugExtend.DrawCircle(end, -up, color, radius, duration, depthTest); DebugExtend.DrawCircle((start + end) * 0.5f, up, color, radius, duration, depthTest); //Side lines Debug.DrawLine(start + right, end + right, color, duration, depthTest); Debug.DrawLine(start - right, end - right, color, duration, depthTest); Debug.DrawLine(start + forward, end + forward, color, duration, depthTest); Debug.DrawLine(start - forward, end - forward, color, duration, depthTest); //Start endcap Debug.DrawLine(start - right, start + right, color, duration, depthTest); Debug.DrawLine(start - forward, start + forward, color, duration, depthTest); //End endcap Debug.DrawLine(end - right, end + right, color, duration, depthTest); Debug.DrawLine(end - forward, end + forward, color, duration, depthTest); }
/// <summary>- Debugs a capsule.</summary> /// <param name='start'>- The position of one end of the capsule.</param> /// <param name='end'>- The position of the other end of the capsule.</param> /// <param name='color'>- The color of the capsule.</param> /// <param name='radius'>- The radius of the capsule.</param> /// <param name='duration'>- How long to draw the capsule.</param> /// <param name='depthTest'>- Whether or not the capsule should be faded when behind other objects.</param> public static void DrawCapsule(Vector3 start, Vector3 end, Color color = default(Color), float radius = 1f, float duration = 0f, bool depthTest = false) { float height = (start - end).magnitude, sideLength = Mathf.Max(0, (height * 0.5f) - radius); Vector3 up = (end - start).normalized * radius, forward = Vector3.Slerp(up, -up, 0.5f), right = Vector3.Cross(up, forward).normalized *radius, middle = (end + start) * 0.5f; start = middle + ((start - middle).normalized * sideLength); end = middle + ((end - middle).normalized * sideLength); color = (color == default(Color)) ? Color.white : color; //Radial circles DebugExtend.DrawCircle(start, up, color, radius, duration, depthTest); DebugExtend.DrawCircle(end, -up, color, radius, duration, depthTest); //Side lines Debug.DrawLine(start + right, end + right, color, duration, depthTest); Debug.DrawLine(start - right, end - right, color, duration, depthTest); Debug.DrawLine(start + forward, end + forward, color, duration, depthTest); Debug.DrawLine(start - forward, end - forward, color, duration, depthTest); for (int i = 1; i < 26; i++) { //Start endcap Debug.DrawLine(Vector3.Slerp(right, -up, i / 25.0f) + start, Vector3.Slerp(right, -up, (i - 1) / 25.0f) + start, color, duration, depthTest); Debug.DrawLine(Vector3.Slerp(-right, -up, i / 25.0f) + start, Vector3.Slerp(-right, -up, (i - 1) / 25.0f) + start, color, duration, depthTest); Debug.DrawLine(Vector3.Slerp(forward, -up, i / 25.0f) + start, Vector3.Slerp(forward, -up, (i - 1) / 25.0f) + start, color, duration, depthTest); Debug.DrawLine(Vector3.Slerp(-forward, -up, i / 25.0f) + start, Vector3.Slerp(-forward, -up, (i - 1) / 25.0f) + start, color, duration, depthTest); //End endcap Debug.DrawLine(Vector3.Slerp(right, up, i / 25.0f) + end, Vector3.Slerp(right, up, (i - 1) / 25.0f) + end, color, duration, depthTest); Debug.DrawLine(Vector3.Slerp(-right, up, i / 25.0f) + end, Vector3.Slerp(-right, up, (i - 1) / 25.0f) + end, color, duration, depthTest); Debug.DrawLine(Vector3.Slerp(forward, up, i / 25.0f) + end, Vector3.Slerp(forward, up, (i - 1) / 25.0f) + end, color, duration, depthTest); Debug.DrawLine(Vector3.Slerp(-forward, up, i / 25.0f) + end, Vector3.Slerp(-forward, up, (i - 1) / 25.0f) + end, color, duration, depthTest); } }