///
/// MIT License - Copyright(c) 2019 Ugo Belfiore
///
using UnityEngine;
using System.Collections;
using System.Reflection;
///
/// Debug Extension
/// - Static class that extends Unity's debugging functionallity.
/// - Attempts to mimic Unity's existing debugging behaviour for ease-of-use.
/// - Includes gizmo drawing methods for less memory-intensive debug visualization.
///
public static class ExtDrawGuizmos
{
///
/// - Debugs a wire sphere.
///
///
/// - The position of the center of the sphere.
///
///
/// - The color of the sphere.
///
///
/// - The radius of the sphere.
///
///
/// - How long to draw the sphere.
///
///
/// - Whether or not the sphere should be faded when behind other objects.
///
public static void DebugWireSphere(Vector3 position, Color color, float radius = 1.0f, float duration = 0, bool depthTest = true)
{
float angle = 10.0f;
Vector3 x = new Vector3(position.x, position.y + radius * Mathf.Sin(0), position.z + radius * Mathf.Cos(0));
Vector3 y = new Vector3(position.x + radius * Mathf.Cos(0), position.y, position.z + radius * Mathf.Sin(0));
Vector3 z = new Vector3(position.x + radius * Mathf.Cos(0), position.y + radius * Mathf.Sin(0), position.z);
Vector3 new_x;
Vector3 new_y;
Vector3 new_z;
for(int i = 1; i < 37; i++){
new_x = new Vector3(position.x, position.y + radius * Mathf.Sin(angle*i*Mathf.Deg2Rad), position.z + radius * Mathf.Cos(angle*i*Mathf.Deg2Rad));
new_y = new Vector3(position.x + radius * Mathf.Cos(angle*i*Mathf.Deg2Rad), position.y, position.z + radius * Mathf.Sin(angle*i*Mathf.Deg2Rad));
new_z = new Vector3(position.x + radius * Mathf.Cos(angle*i*Mathf.Deg2Rad), position.y + radius * Mathf.Sin(angle*i*Mathf.Deg2Rad), position.z);
Debug.DrawLine(x, new_x, color, duration, depthTest);
Debug.DrawLine(y, new_y, color, duration, depthTest);
Debug.DrawLine(z, new_z, color, duration, depthTest);
x = new_x;
y = new_y;
z = new_z;
}
}
public static void DebugCross(Transform transform, float lenght = 1, float duration = 1)
{
Debug.DrawRay(transform.position, transform.up * lenght, Color.green);
Debug.DrawRay(transform.position, transform.forward * lenght, Color.blue);
Debug.DrawRay(transform.transform.position, transform.right * lenght, Color.red);
}
public static void DebugCross(Vector3 position, Quaternion rotation, float lenght = 1, float duration = 1)
{
Debug.DrawRay(position, rotation * Vector3.up * lenght, Color.green);
Debug.DrawRay(position, rotation * Vector3.forward * lenght, Color.blue);
Debug.DrawRay(position, rotation * Vector3.right * lenght, Color.red);
}
}