mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-10 02:45:41 +00:00
Remove Box2D struct, use built in Rect(angle/F)
This commit is contained in:
parent
96170eac6f
commit
75b79589e8
@ -1,160 +0,0 @@
|
||||
using System.Drawing;
|
||||
using UnityEngine;
|
||||
|
||||
namespace X10D.Unity;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a 2D box that can be drawn using the <see cref="DebugEx" /> class.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This structure serves no real purpose except to be used in tandem with <see cref="DebugEx" />. For creating a logical
|
||||
/// rectangle, consider using the <see cref="Rectangle" />, <see cref="RectangleF" />, <see cref="Rect" />, or
|
||||
/// <see cref="RectInt" /> structures.
|
||||
/// </remarks>
|
||||
public readonly struct Box2D
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Box2D" /> struct.
|
||||
/// </summary>
|
||||
/// <param name="origin">The origin of the box.</param>
|
||||
/// <param name="halfExtents">The half extents of the box.</param>
|
||||
public Box2D(Vector2 origin, Vector2 halfExtents)
|
||||
{
|
||||
LocalTopLeft = new Vector2(-halfExtents.x, halfExtents.y);
|
||||
LocalTopRight = new Vector2(halfExtents.x, halfExtents.y);
|
||||
LocalBottomLeft = new Vector2(-halfExtents.x, -halfExtents.y);
|
||||
LocalBottomRight = new Vector2(halfExtents.x, -halfExtents.y);
|
||||
|
||||
Origin = origin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Box2D" /> struct.
|
||||
/// </summary>
|
||||
/// <param name="origin">The origin of the box.</param>
|
||||
/// <param name="halfExtents">The half extents of the box.</param>
|
||||
/// <param name="rotation">The rotation of the box.</param>
|
||||
public Box2D(Vector2 origin, Vector2 halfExtents, float rotation)
|
||||
: this(origin, halfExtents)
|
||||
{
|
||||
var localTopLeft = new Vector2(-halfExtents.x, halfExtents.y);
|
||||
var localTopRight = new Vector2(halfExtents.x, halfExtents.y);
|
||||
var localBottomLeft = new Vector2(-halfExtents.x, -halfExtents.y);
|
||||
var localBottomRight = new Vector2(halfExtents.x, -halfExtents.y);
|
||||
|
||||
Rotate(
|
||||
rotation,
|
||||
ref localTopLeft,
|
||||
ref localTopRight,
|
||||
ref localBottomLeft,
|
||||
ref localBottomRight);
|
||||
|
||||
LocalTopLeft = localTopLeft;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the origin of the box.
|
||||
/// </summary>
|
||||
/// <value>The origin.</value>
|
||||
public Vector2 Origin { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the top-left corner of the box, in local space.
|
||||
/// </summary>
|
||||
/// <value>The top-left corner.</value>
|
||||
public Vector2 LocalTopLeft { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the top-right corner of the box, in local space.
|
||||
/// </summary>
|
||||
/// <value>The top-right corner.</value>
|
||||
public Vector2 LocalTopRight { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bottom-left corner of the box, in local space.
|
||||
/// </summary>
|
||||
/// <value>The bottom-left corner.</value>
|
||||
public Vector2 LocalBottomLeft { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bottom-right corner of the box, in local space.
|
||||
/// </summary>
|
||||
/// <value>The bottom-right corner.</value>
|
||||
public Vector2 LocalBottomRight { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the top-left corner of the box, in world space.
|
||||
/// </summary>
|
||||
/// <value>The top-left corner.</value>
|
||||
public Vector2 TopLeft
|
||||
{
|
||||
get => LocalTopLeft + Origin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the top-right corner of the box, in world space.
|
||||
/// </summary>
|
||||
/// <value>The top-right corner.</value>
|
||||
public Vector2 TopRight
|
||||
{
|
||||
get => LocalTopRight + Origin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bottom-left corner of the box, in world space.
|
||||
/// </summary>
|
||||
/// <value>The bottom-left corner.</value>
|
||||
public Vector2 BottomLeft
|
||||
{
|
||||
get => LocalBottomLeft + Origin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bottom-right corner of the box, in world space.
|
||||
/// </summary>
|
||||
/// <value>The bottom-right corner.</value>
|
||||
public Vector2 BottomRight
|
||||
{
|
||||
get => LocalBottomRight + Origin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts an instance of <see cref="Rect" /> to an instance of <see cref="Box2D" />.
|
||||
/// </summary>
|
||||
/// <param name="rect">The <see cref="Rect" /> to convert.</param>
|
||||
/// <returns>A new instance of <see cref="Box2D" />.</returns>
|
||||
public static implicit operator Box2D(Rect rect)
|
||||
{
|
||||
return new Box2D(rect.center, rect.size / 2f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts an instance of <see cref="RectInt" /> to an instance of <see cref="Box2D" />.
|
||||
/// </summary>
|
||||
/// <param name="rect">The <see cref="RectInt" /> to convert.</param>
|
||||
/// <returns>A new instance of <see cref="Box2D" />.</returns>
|
||||
public static implicit operator Box2D(RectInt rect)
|
||||
{
|
||||
return new Box2D(rect.center, (Vector2)rect.size / 2.0f);
|
||||
}
|
||||
|
||||
private static Vector2 RotatePointAroundPivot(Vector2 point, Vector2 pivot, float rotation)
|
||||
{
|
||||
Vector2 direction = point - pivot;
|
||||
return pivot + (rotation * direction);
|
||||
}
|
||||
|
||||
private static void Rotate(
|
||||
float rotation,
|
||||
ref Vector2 localTopLeft,
|
||||
ref Vector2 localTopRight,
|
||||
ref Vector2 localBottomLeft,
|
||||
ref Vector2 localBottomRight
|
||||
)
|
||||
{
|
||||
localTopLeft = RotatePointAroundPivot(localTopLeft, Vector2.zero, rotation);
|
||||
localTopRight = RotatePointAroundPivot(localTopRight, Vector2.zero, rotation);
|
||||
localBottomLeft = RotatePointAroundPivot(localBottomLeft, Vector2.zero, rotation);
|
||||
localBottomRight = RotatePointAroundPivot(localBottomRight, Vector2.zero, rotation);
|
||||
}
|
||||
}
|
@ -1,333 +0,0 @@
|
||||
using System.Drawing;
|
||||
using UnityEngine;
|
||||
using X10D.Unity.Drawing;
|
||||
using Color = UnityEngine.Color;
|
||||
|
||||
namespace X10D.Unity;
|
||||
|
||||
public static partial class DebugEx
|
||||
{
|
||||
/// <summary>
|
||||
/// Draws a rectangle.
|
||||
/// </summary>
|
||||
/// <param name="center">The center point.</param>
|
||||
/// <param name="halfExtents">The extents of the box, halved.</param>
|
||||
public static void DrawRectangle(Vector2 center, Vector2 halfExtents)
|
||||
{
|
||||
DrawRectangle(center, halfExtents, Color.white, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified rotation.
|
||||
/// </summary>
|
||||
/// <param name="center">The center point.</param>
|
||||
/// <param name="halfExtents">The extents of the box, halved.</param>
|
||||
/// <param name="rotation">The rotation of the box.</param>
|
||||
public static void DrawRectangle(Vector2 center, Vector2 halfExtents, float rotation)
|
||||
{
|
||||
DrawRectangle(new Box2D(center, halfExtents, rotation), Color.white, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color.
|
||||
/// </summary>
|
||||
/// <param name="center">The center point.</param>
|
||||
/// <param name="halfExtents">The extents of the box, halved.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
public static void DrawRectangle(Vector2 center, Vector2 halfExtents, in Color color)
|
||||
{
|
||||
DrawRectangle(center, halfExtents, color, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified rotation and color.
|
||||
/// </summary>
|
||||
/// <param name="center">The center point.</param>
|
||||
/// <param name="halfExtents">The extents of the box, halved.</param>
|
||||
/// <param name="rotation">The rotation of the box.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
public static void DrawRectangle(Vector2 center, Vector2 halfExtents, float rotation, in Color color)
|
||||
{
|
||||
DrawRectangle(new Box2D(center, halfExtents, rotation), color, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="center">The center point.</param>
|
||||
/// <param name="halfExtents">The extents of the box, halved.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
public static void DrawRectangle(Vector2 center, Vector2 halfExtents, in Color color, float duration)
|
||||
{
|
||||
DrawRectangle(center, halfExtents, color, duration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified rotation, color, and duration.
|
||||
/// </summary>
|
||||
/// <param name="center">The center point.</param>
|
||||
/// <param name="halfExtents">The extents of the box, halved.</param>
|
||||
/// <param name="rotation">The rotation of the box.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
public static void DrawRectangle(Vector2 center, Vector2 halfExtents, float rotation, in Color color, float duration)
|
||||
{
|
||||
DrawRectangle(new Box2D(center, halfExtents, rotation), color, duration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="center">The center point.</param>
|
||||
/// <param name="halfExtents">The extents of the box, halved.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
/// <param name="depthTest">
|
||||
/// <see langword="DefaultDepthTest" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
|
||||
/// <see langword="DefaultDepthTest" /> will have the box be obscured by objects closer to the camera.
|
||||
/// </param>
|
||||
public static void DrawRectangle(Vector2 center, Vector2 halfExtents, in Color color, float duration, bool depthTest)
|
||||
{
|
||||
DrawRectangle(new Box2D(center, halfExtents), color, duration, depthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified rotation, color, and duration.
|
||||
/// </summary>
|
||||
/// <param name="center">The center point.</param>
|
||||
/// <param name="halfExtents">The extents of the box, halved.</param>
|
||||
/// <param name="rotation">The rotation of the box.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
/// <param name="depthTest">
|
||||
/// <see langword="DefaultDepthTest" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
|
||||
/// <see langword="DefaultDepthTest" /> will have the box be obscured by objects closer to the camera.
|
||||
/// </param>
|
||||
public static void DrawRectangle(Vector2 center, Vector2 halfExtents, float rotation, in Color color, float duration,
|
||||
bool depthTest)
|
||||
{
|
||||
DrawRectangle(new Box2D(center, halfExtents, rotation), color, duration, depthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color.
|
||||
/// </summary>
|
||||
/// <param name="box">The box to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
public static void DrawRectangle(Box2D box, in Color color)
|
||||
{
|
||||
DrawRectangle(box, color, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="box">The box to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
public static void DrawRectangle(Box2D box, in Color color, float duration)
|
||||
{
|
||||
DrawRectangle(box, color, duration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="box">The box to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
/// <param name="depthTest">
|
||||
/// <see langword="DefaultDepthTest" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
|
||||
/// <see langword="DefaultDepthTest" /> will have the box be obscured by objects closer to the camera.
|
||||
/// </param>
|
||||
public static void DrawRectangle(Box2D box, in Color color, float duration, bool depthTest)
|
||||
{
|
||||
Debug.DrawLine(box.TopLeft, box.TopRight, color, duration, depthTest);
|
||||
Debug.DrawLine(box.TopRight, box.BottomRight, color, duration, depthTest);
|
||||
Debug.DrawLine(box.BottomRight, box.BottomLeft, color, duration, depthTest);
|
||||
Debug.DrawLine(box.BottomLeft, box.TopLeft, color, duration, depthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
public static void DrawRectangle(Rect rect, in Color color)
|
||||
{
|
||||
DrawRectangle(rect, color, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
public static void DrawRectangle(Rect rect, in Color color, float duration)
|
||||
{
|
||||
DrawRectangle(rect, color, duration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
/// <param name="depthTest">
|
||||
/// <see langword="DefaultDepthTest" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
|
||||
/// <see langword="DefaultDepthTest" /> will have the box be obscured by objects closer to the camera.
|
||||
/// </param>
|
||||
public static void DrawRectangle(Rect rect, in Color color, float duration, bool depthTest)
|
||||
{
|
||||
var box = new Box2D(rect.center, rect.size / 2.0f);
|
||||
DrawRectangle(box, color, duration, depthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
public static void DrawRectangle(RectInt rect, in Color color)
|
||||
{
|
||||
DrawRectangle(rect, color, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
public static void DrawRectangle(RectInt rect, in Color color, float duration)
|
||||
{
|
||||
DrawRectangle(rect, color, duration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
/// <param name="depthTest">
|
||||
/// <see langword="DefaultDepthTest" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
|
||||
/// <see langword="DefaultDepthTest" /> will have the box be obscured by objects closer to the camera.
|
||||
/// </param>
|
||||
public static void DrawRectangle(RectInt rect, in Color color, float duration, bool depthTest)
|
||||
{
|
||||
var box = new Box2D(rect.center, (Vector2)rect.size / 2.0f);
|
||||
DrawRectangle(box, color, duration, depthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
public static void DrawRectangle(Rectangle rect, in Color color)
|
||||
{
|
||||
DrawRectangle(rect, color, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
public static void DrawRectangle(Rectangle rect, in Color color, float duration)
|
||||
{
|
||||
DrawRectangle(rect, color, duration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
/// <param name="depthTest">
|
||||
/// <see langword="DefaultDepthTest" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
|
||||
/// <see langword="DefaultDepthTest" /> will have the box be obscured by objects closer to the camera.
|
||||
/// </param>
|
||||
public static void DrawRectangle(Rectangle rect, in Color color, float duration, bool depthTest)
|
||||
{
|
||||
var origin = new Vector2(rect.X + rect.Width / 2.0f, rect.Y + rect.Height / 2.0f);
|
||||
Vector2 halfExtents = rect.Size.ToUnityVector2() / 2.0f;
|
||||
|
||||
var box = new Box2D(origin, halfExtents);
|
||||
DrawRectangle(box, color, duration, depthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
public static void DrawRectangle(RectangleF rect, in Color color)
|
||||
{
|
||||
DrawRectangle(rect, color, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
public static void DrawRectangle(RectangleF rect, in Color color, float duration)
|
||||
{
|
||||
DrawRectangle(rect, color, duration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
/// <param name="depthTest">
|
||||
/// <see langword="DefaultDepthTest" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
|
||||
/// <see langword="DefaultDepthTest" /> will have the box be obscured by objects closer to the camera.
|
||||
/// </param>
|
||||
public static void DrawRectangle(RectangleF rect, in Color color, float duration, bool depthTest)
|
||||
{
|
||||
var origin = new Vector2(rect.X + rect.Width / 2.0f, rect.Y + rect.Height / 2.0f);
|
||||
Vector2 halfExtents = rect.Size.ToUnityVector2() / 2.0f;
|
||||
|
||||
var box = new Box2D(origin, halfExtents);
|
||||
DrawRectangle(box, color, duration, depthTest);
|
||||
}
|
||||
}
|
234
X10D.Unity/src/DebugEx.Rectangle.cs
Normal file
234
X10D.Unity/src/DebugEx.Rectangle.cs
Normal file
@ -0,0 +1,234 @@
|
||||
using System.Drawing;
|
||||
using UnityEngine;
|
||||
using X10D.Unity.Drawing;
|
||||
using Color = UnityEngine.Color;
|
||||
|
||||
namespace X10D.Unity;
|
||||
|
||||
public static partial class DebugEx
|
||||
{
|
||||
/// <summary>
|
||||
/// Draws a rectangle.
|
||||
/// </summary>
|
||||
/// <param name="center">The center point.</param>
|
||||
/// <param name="size">The extents of the box.</param>
|
||||
public static void DrawRectangle(Vector2 center, Vector2 size)
|
||||
{
|
||||
DrawRectangle(center, size, Color.white, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color.
|
||||
/// </summary>
|
||||
/// <param name="center">The center point.</param>
|
||||
/// <param name="size">The extents of the box.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
public static void DrawRectangle(Vector2 center, Vector2 size, in Color color)
|
||||
{
|
||||
DrawRectangle(center, size, color, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="center">The center point.</param>
|
||||
/// <param name="size">The extents of the box.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
public static void DrawRectangle(Vector2 center, Vector2 size, in Color color, float duration)
|
||||
{
|
||||
DrawRectangle(center, size, color, duration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="center">The center point.</param>
|
||||
/// <param name="size">The extents of the box.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
/// <param name="depthTest">
|
||||
/// <see langword="DefaultDepthTest" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
|
||||
/// <see langword="DefaultDepthTest" /> will have the box be obscured by objects closer to the camera.
|
||||
/// </param>
|
||||
public static void DrawRectangle(Vector2 center, Vector2 size, in Color color, float duration, bool depthTest)
|
||||
{
|
||||
DrawRectangle(new Rect(center, size), color, duration, depthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
public static void DrawRectangle(Rect rect, in Color color)
|
||||
{
|
||||
DrawRectangle(rect, color, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
public static void DrawRectangle(Rect rect, in Color color, float duration)
|
||||
{
|
||||
DrawRectangle(rect, color, duration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
/// <param name="depthTest">
|
||||
/// <see langword="DefaultDepthTest" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
|
||||
/// <see langword="DefaultDepthTest" /> will have the box be obscured by objects closer to the camera.
|
||||
/// </param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
public static void DrawRectangle(RectInt rect, in Color color)
|
||||
{
|
||||
DrawRectangle(rect, color, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
public static void DrawRectangle(RectInt rect, in Color color, float duration)
|
||||
{
|
||||
DrawRectangle(rect, color, duration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
/// <param name="depthTest">
|
||||
/// <see langword="DefaultDepthTest" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
|
||||
/// <see langword="DefaultDepthTest" /> will have the box be obscured by objects closer to the camera.
|
||||
/// </param>
|
||||
public static void DrawRectangle(RectInt rect, in Color color, float duration, bool depthTest)
|
||||
{
|
||||
DrawRectangle(new Rect(rect.center, rect.size), color, duration, depthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color.
|
||||
/// </summary>
|
||||
/// <param name="rectangle">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
public static void DrawRectangle(Rectangle rectangle, in Color color)
|
||||
{
|
||||
DrawRectangle(rectangle, color, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rectangle">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
public static void DrawRectangle(Rectangle rectangle, in Color color, float duration)
|
||||
{
|
||||
DrawRectangle(rectangle, color, duration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rectangle">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
/// <param name="depthTest">
|
||||
/// <see langword="DefaultDepthTest" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
|
||||
/// <see langword="DefaultDepthTest" /> will have the box be obscured by objects closer to the camera.
|
||||
/// </param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color.
|
||||
/// </summary>
|
||||
/// <param name="rectangle">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
public static void DrawRectangle(RectangleF rectangle, in Color color)
|
||||
{
|
||||
DrawRectangle(rectangle, color, DefaultDrawDuration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rectangle">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
public static void DrawRectangle(RectangleF rectangle, in Color color, float duration)
|
||||
{
|
||||
DrawRectangle(rectangle, color, duration, DefaultDepthTest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rectangle with the specified color and duration.
|
||||
/// </summary>
|
||||
/// <param name="rectangle">The rectangle to draw.</param>
|
||||
/// <param name="color">The color of the box.</param>
|
||||
/// <param name="duration">
|
||||
/// The duration of the box's visibility, in seconds. If 0 is passed, the box is visible for a single frame.
|
||||
/// </param>
|
||||
/// <param name="depthTest">
|
||||
/// <see langword="DefaultDepthTest" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
|
||||
/// <see langword="DefaultDepthTest" /> will have the box be obscured by objects closer to the camera.
|
||||
/// </param>
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user