51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
public static class DebugUtilities
|
|
{
|
|
/// <summary>
|
|
/// Draws a wire sphere using Debug.DrawLine for runtime visibility.
|
|
/// </summary>
|
|
public static void DrawWireSphere(Vector3 center, float radius, Color color, float duration, int quality = 3)
|
|
{
|
|
quality = Mathf.Clamp(quality, 1, 10);
|
|
int segments = quality << 2;
|
|
int subdivisions = quality << 3;
|
|
int halfSegments = segments >> 1;
|
|
float strideAngle = 360f / subdivisions;
|
|
float segmentStride = 180f / segments;
|
|
|
|
Vector3 first;
|
|
Vector3 next;
|
|
|
|
// Draw meridians (vertical circles)
|
|
for (int i = 0; i < segments; i++)
|
|
{
|
|
first = (Vector3.forward * radius);
|
|
first = Quaternion.AngleAxis(segmentStride * (i - halfSegments), Vector3.right) * first;
|
|
|
|
for (int j = 0; j < subdivisions; j++)
|
|
{
|
|
next = Quaternion.AngleAxis(strideAngle, Vector3.up) * first;
|
|
Debug.DrawLine(first + center, next + center, color, duration);
|
|
first = next;
|
|
}
|
|
}
|
|
|
|
// Draw parallels (horizontal circles)
|
|
Vector3 axis;
|
|
for (int i = 0; i < segments; i++)
|
|
{
|
|
first = (Vector3.forward * radius);
|
|
first = Quaternion.AngleAxis(segmentStride * (i - halfSegments), Vector3.up) * first;
|
|
axis = Quaternion.AngleAxis(90f, Vector3.up) * first;
|
|
|
|
for (int j = 0; j < subdivisions; j++)
|
|
{
|
|
next = Quaternion.AngleAxis(strideAngle, axis) * first;
|
|
Debug.DrawLine(first + center, next + center, color, duration);
|
|
first = next;
|
|
}
|
|
}
|
|
}
|
|
}
|