using System.Drawing;
using UnityEngine;
using X10D.Unity.Drawing;
using Color = UnityEngine.Color;
namespace X10D.Unity;
public static partial class DebugUtility
{
///
/// Draws a rectangle.
///
/// The center point.
/// The extents of the box.
public static void DrawRectangle(Vector2 center, Vector2 size)
{
DrawRectangle(center, size, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
///
/// Draws a rectangle with the specified color.
///
/// The center point.
/// The extents of the box.
/// The color of the box.
public static void DrawRectangle(Vector2 center, Vector2 size, in Color color)
{
DrawRectangle(center, size, color, DefaultDrawDuration, DefaultDepthTest);
}
///
/// Draws a rectangle with the specified color and duration.
///
/// The center point.
/// The extents of the box.
/// The color of the box.
///
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
///
public static void DrawRectangle(Vector2 center, Vector2 size, in Color color, float duration)
{
DrawRectangle(center, size, color, duration, DefaultDepthTest);
}
///
/// Draws a rectangle with the specified color and duration.
///
/// The center point.
/// The extents of the box.
/// The color of the box.
///
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
///
///
/// if depth test should be applied; otherwise, . Passing
/// will have the box be obscured by objects closer to the camera.
///
public static void DrawRectangle(Vector2 center, Vector2 size, in Color color, float duration, bool depthTest)
{
DrawRectangle(new Rect(center, size), color, duration, depthTest);
}
///
/// Draws a rectangle with the specified color.
///
/// The rectangle to draw.
/// The color of the box.
public static void DrawRectangle(Rect rect, in Color color)
{
DrawRectangle(rect, color, DefaultDrawDuration, DefaultDepthTest);
}
///
/// Draws a rectangle with the specified color and duration.
///
/// The rectangle to draw.
/// The color of the box.
///
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
///
public static void DrawRectangle(Rect rect, in Color color, float duration)
{
DrawRectangle(rect, color, duration, DefaultDepthTest);
}
///
/// Draws a rectangle with the specified color and duration.
///
/// The rectangle to draw.
/// The color of the box.
///
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
///
///
/// if depth test should be applied; otherwise, . Passing
/// will have the box be obscured by objects closer to the camera.
///
public static void DrawRectangle(Rect rect, in Color color, float duration, bool depthTest)
{
var topLeft = new Vector2(rect.xMin, rect.yMin);
var topRight = new Vector2(rect.xMax, rect.yMin);
var bottomLeft = new Vector2(rect.xMin, rect.yMax);
var bottomRight = new Vector2(rect.xMax, rect.yMax);
DrawLine(topLeft, topRight, color, duration, depthTest);
DrawLine(topRight, bottomRight, color, duration, depthTest);
DrawLine(bottomRight, bottomLeft, color, duration, depthTest);
DrawLine(bottomLeft, topLeft, color, duration, depthTest);
}
///
/// Draws a rectangle with the specified color.
///
/// The rectangle to draw.
/// The color of the box.
public static void DrawRectangle(RectInt rect, in Color color)
{
DrawRectangle(rect, color, DefaultDrawDuration, DefaultDepthTest);
}
///
/// Draws a rectangle with the specified color and duration.
///
/// The rectangle to draw.
/// The color of the box.
///
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
///
public static void DrawRectangle(RectInt rect, in Color color, float duration)
{
DrawRectangle(rect, color, duration, DefaultDepthTest);
}
///
/// Draws a rectangle with the specified color and duration.
///
/// The rectangle to draw.
/// The color of the box.
///
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
///
///
/// if depth test should be applied; otherwise, . Passing
/// will have the box be obscured by objects closer to the camera.
///
public static void DrawRectangle(RectInt rect, in Color color, float duration, bool depthTest)
{
DrawRectangle(new Rect(rect.center, rect.size), color, duration, depthTest);
}
///
/// Draws a rectangle with the specified color.
///
/// The rectangle to draw.
/// The color of the box.
public static void DrawRectangle(Rectangle rectangle, in Color color)
{
DrawRectangle(rectangle, color, DefaultDrawDuration, DefaultDepthTest);
}
///
/// Draws a rectangle with the specified color and duration.
///
/// The rectangle to draw.
/// The color of the box.
///
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
///
public static void DrawRectangle(Rectangle rectangle, in Color color, float duration)
{
DrawRectangle(rectangle, color, duration, DefaultDepthTest);
}
///
/// Draws a rectangle with the specified color and duration.
///
/// The rectangle to draw.
/// The color of the box.
///
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
///
///
/// if depth test should be applied; otherwise, . Passing
/// will have the box be obscured by objects closer to the camera.
///
public static void DrawRectangle(Rectangle rectangle, in Color color, float duration, bool depthTest)
{
var origin = new Vector2(rectangle.X + rectangle.Width / 2.0f, rectangle.Y + rectangle.Height / 2.0f);
var rect = new Rect(origin, rectangle.Size.ToUnityVector2());
DrawRectangle(rect, color, duration, depthTest);
}
///
/// Draws a rectangle with the specified color.
///
/// The rectangle to draw.
/// The color of the box.
public static void DrawRectangle(RectangleF rectangle, in Color color)
{
DrawRectangle(rectangle, color, DefaultDrawDuration, DefaultDepthTest);
}
///
/// Draws a rectangle with the specified color and duration.
///
/// The rectangle to draw.
/// The color of the box.
///
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
///
public static void DrawRectangle(RectangleF rectangle, in Color color, float duration)
{
DrawRectangle(rectangle, color, duration, DefaultDepthTest);
}
///
/// Draws a rectangle with the specified color and duration.
///
/// The rectangle to draw.
/// The color of the box.
///
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
///
///
/// if depth test should be applied; otherwise, . Passing
/// will have the box be obscured by objects closer to the camera.
///
public static void DrawRectangle(RectangleF rectangle, in Color color, float duration, bool depthTest)
{
var origin = new Vector2(rectangle.X + rectangle.Width / 2.0f, rectangle.Y + rectangle.Height / 2.0f);
var rect = new Rect(origin, rectangle.Size.ToUnityVector2());
DrawRectangle(rect, color, duration, depthTest);
}
}