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

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Static class for adding More Debug funtions
/// </summary>
public static class DebugExtensions
{
/// <summary>
/// Draws wireframe cube in scene view
/// </summary>
/// <param name="Position">Centre of cube</param>
/// <param name="Extent">extent of cube (half of size)</param>
/// <param name="color">Color of lines</param>
/// <param name="duration">Amount of time cube is displayed</param>
/// <param name="depthTest">Should cube be obsured by otherobjects</param>
public static void DrawCube(Vector3 Position, Vector3 Extent, Color color, float duration, bool depthTest = true)
{
Vector3 min = Position - Extent;
Vector3 max = Position + Extent;
//Draw bottom Square
Debug.DrawLine(new Vector3(min.x, min.y, min.z), new Vector3(min.x, min.y, max.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(min.x, min.y, max.z), new Vector3(max.x, min.y, max.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(max.x, min.y, max.z), new Vector3(max.x, min.y, min.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(max.x, min.y, min.z), new Vector3(min.x, min.y, min.z), color, duration, depthTest);
//top square
Debug.DrawLine(new Vector3(min.x, max.y, min.z), new Vector3(min.x, max.y, max.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(min.x, max.y, max.z), new Vector3(max.x, max.y, max.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(max.x, max.y, max.z), new Vector3(max.x, max.y, min.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(max.x, max.y, min.z), new Vector3(min.x, max.y, min.z), color, duration, depthTest);
//connect top and bottom
Debug.DrawLine(new Vector3(min.x, min.y, min.z), new Vector3(min.x, max.y, min.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(min.x, min.y, max.z), new Vector3(min.x, max.y, max.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(max.x, min.y, max.z), new Vector3(max.x, max.y, max.z), color, duration, depthTest);
Debug.DrawLine(new Vector3(max.x, min.y, min.z), new Vector3(max.x, max.y, min.z), color, duration, depthTest);
}
/// <summary>
/// Draws wireframe cube in scene view
/// </summary>
/// <param name="Position">Centre of cube</param>
/// <param name="Extent">extent of cube (half of size)</param>
/// <param name="color">Color of lines</param>
/// <param name="duration">Amount of time cube is displayed</param>
public static void DrawCube(Vector3 Position, float Extent, Color color, float duration)
{
//Call overload funtion
DrawCube(Position, Vector3.one * Extent, color, duration);
}
/// <summary>
/// Draws wireframe around a RectTransform in scene view
/// </summary>
/// <param name="transform">Rect transform to draw around</param>
/// <param name="color">Color of the lines</param>
/// <param name="duration">How long the lines should be visible for</param>
/// <param name="depthTest">Should the lines be obscured by objects closer to the camera</param>
public static void DrawRect(RectTransform transform, Color color, float duration = 0.0f, bool depthTest = false)
{
Rect rect = transform.GlobalRect();
Debug.DrawLine(new Vector3(rect.min.x, rect.max.y, 0), new Vector3(rect.max.x, rect.max.y, 0), color, duration, depthTest);
Debug.DrawLine(new Vector3(rect.max.x, rect.max.y, 0), new Vector3(rect.max.x, rect.min.y, 0), color, duration, depthTest);
Debug.DrawLine(new Vector3(rect.max.x, rect.min.y, 0), new Vector3(rect.min.x, rect.min.y, 0), color, duration, depthTest);
Debug.DrawLine(new Vector3(rect.min.x, rect.min.y, 0), new Vector3(rect.min.x, rect.max.y, 0), color, duration, depthTest);
}
}//End DebugExtentions