1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 19:58:49 +00:00

Add DebugEx class

This commit is contained in:
Oliver Booth 2022-06-01 19:00:36 +01:00
parent f5af7b9513
commit 32485b727a
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
13 changed files with 2912 additions and 0 deletions

View File

@ -18,6 +18,7 @@
- X10D: Added `Vector2.ToSizeF()`
- X10D: Added `Vector3.Deconstruct()`
- X10D: Added `Vector4.Deconstruct()`
- X10D.Unity: Added `DebugEx`, which mimics `UnityEngine.Debug` while offering more useful primitive drawing methods
- X10D.Unity: Added `System.Drawing.Color.ToUnityColor()`
- X10D.Unity: Added `System.Drawing.Color.ToUnityColor32()`
- X10D.Unity: Added `Color.ToSystemDrawingColor()`

231
X10D.Unity/src/Box.cs Normal file
View File

@ -0,0 +1,231 @@
using UnityEngine;
using X10D.Drawing;
namespace X10D.Unity;
/// <summary>
/// Represents a 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
/// cuboid, consider using the <see cref="Cuboid" /> structure.
/// </remarks>
public readonly struct Box
{
/// <summary>
/// Initializes a new instance of the <see cref="Box" /> struct.
/// </summary>
/// <param name="origin">The origin of the box.</param>
/// <param name="halfExtents">The half extents of the box.</param>
public Box(Vector3 origin, Vector3 halfExtents)
{
LocalFrontTopLeft = new Vector3(-halfExtents.x, halfExtents.y, -halfExtents.z);
LocalFrontTopRight = new Vector3(halfExtents.x, halfExtents.y, -halfExtents.z);
LocalFrontBottomLeft = new Vector3(-halfExtents.x, -halfExtents.y, -halfExtents.z);
LocalFrontBottomRight = new Vector3(halfExtents.x, -halfExtents.y, -halfExtents.z);
Origin = origin;
}
/// <summary>
/// Initializes a new instance of the <see cref="Box" /> struct.
/// </summary>
/// <param name="origin">The origin of the box.</param>
/// <param name="halfExtents">The half extents of the box.</param>
/// <param name="orientation">The orientation of the box.</param>
public Box(Vector3 origin, Vector3 halfExtents, Quaternion orientation)
: this(origin, halfExtents)
{
var localFrontTopLeft = new Vector3(-halfExtents.x, halfExtents.y, -halfExtents.z);
var localFrontTopRight = new Vector3(halfExtents.x, halfExtents.y, -halfExtents.z);
var localFrontBottomLeft = new Vector3(-halfExtents.x, -halfExtents.y, -halfExtents.z);
var localFrontBottomRight = new Vector3(halfExtents.x, -halfExtents.y, -halfExtents.z);
Rotate(
orientation,
ref localFrontTopLeft,
ref localFrontTopRight,
ref localFrontBottomLeft,
ref localFrontBottomRight);
LocalFrontTopLeft = localFrontTopLeft;
}
/// <summary>
/// Gets the origin of the box.
/// </summary>
/// <value>The origin.</value>
public Vector3 Origin { get; }
/// <summary>
/// Gets the front-top-left corner of the box, in local space.
/// </summary>
/// <value>The front-top-left corner.</value>
public Vector3 LocalFrontTopLeft { get; }
/// <summary>
/// Gets the front-top-right corner of the box, in local space.
/// </summary>
/// <value>The front-top-right corner.</value>
public Vector3 LocalFrontTopRight { get; }
/// <summary>
/// Gets the front-bottom-left corner of the box, in local space.
/// </summary>
/// <value>The front-bottom-left corner.</value>
public Vector3 LocalFrontBottomLeft { get; }
/// <summary>
/// Gets the front-bottom-right corner of the box, in local space.
/// </summary>
/// <value>The front-bottom-right corner.</value>
public Vector3 LocalFrontBottomRight { get; }
/// <summary>
/// Gets the back-top-left corner of the box, in local space.
/// </summary>
/// <value>The back-top-left corner.</value>
public Vector3 LocalBackTopLeft
{
get => -LocalFrontBottomRight;
}
/// <summary>
/// Gets the back-top-right corner of the box, in local space.
/// </summary>
/// <value>The back-top-right corner.</value>
public Vector3 LocalBackTopRight
{
get => -LocalFrontBottomLeft;
}
/// <summary>
/// Gets the back-bottom-left corner of the box, in local space.
/// </summary>
/// <value>The back-bottom-left corner.</value>
public Vector3 LocalBackBottomLeft
{
get => -LocalFrontTopRight;
}
/// <summary>
/// Gets the back-bottom-right corner of the box, in local space.
/// </summary>
/// <value>The back-bottom-right corner.</value>
public Vector3 LocalBackBottomRight
{
get => -LocalFrontTopLeft;
}
/// <summary>
/// Gets the front-top-left corner of the box, in world space.
/// </summary>
/// <value>The front-top-left corner.</value>
public Vector3 FrontTopLeft
{
get => LocalFrontTopLeft + Origin;
}
/// <summary>
/// Gets the front-top-right corner of the box, in world space.
/// </summary>
/// <value>The front-top-right corner.</value>
public Vector3 FrontTopRight
{
get => LocalFrontTopRight + Origin;
}
/// <summary>
/// Gets the front-bottom-left corner of the box, in world space.
/// </summary>
/// <value>The front-bottom-left corner.</value>
public Vector3 FrontBottomLeft
{
get => LocalFrontBottomLeft + Origin;
}
/// <summary>
/// Gets the front-bottom-right corner of the box, in world space.
/// </summary>
/// <value>The front-bottom-right corner.</value>
public Vector3 FrontBottomRight
{
get => LocalFrontBottomRight + Origin;
}
/// <summary>
/// Gets the back-bottom-left corner of the box, in world space.
/// </summary>
/// <value>The back-bottom-left corner.</value>
public Vector3 BackTopLeft
{
get => LocalBackTopLeft + Origin;
}
/// <summary>
/// Gets the back-bottom-right corner of the box, in world space.
/// </summary>
/// <value>The back-bottom-right corner.</value>
public Vector3 BackTopRight
{
get => LocalBackTopRight + Origin;
}
/// <summary>
/// Gets the back-bottom-right corner of the box, in world space.
/// </summary>
/// <value>The back-bottom-right corner.</value>
public Vector3 BackBottomLeft
{
get => LocalBackBottomLeft + Origin;
}
/// <summary>
/// Gets the back-bottom-right corner of the box, in world space.
/// </summary>
/// <value>The back-bottom-right corner.</value>
public Vector3 BackBottomRight
{
get => LocalBackBottomRight + Origin;
}
/// <summary>
/// Implicitly converts an instance of <see cref="Bounds" /> to an instance of <see cref="Box" />.
/// </summary>
/// <param name="bounds">The <see cref="Bounds" /> to convert.</param>
/// <returns>A new instance of <see cref="Box" />.</returns>
public static implicit operator Box(Bounds bounds)
{
return new Box(bounds.center, bounds.extents);
}
/// <summary>
/// Implicitly converts an instance of <see cref="Bounds" /> to an instance of <see cref="Box" />.
/// </summary>
/// <param name="bounds">The <see cref="Bounds" /> to convert.</param>
/// <returns>A new instance of <see cref="Box" />.</returns>
public static implicit operator Box(BoundsInt bounds)
{
return new Box(bounds.center, (Vector3)bounds.size / 2.0f);
}
private static Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Quaternion rotation)
{
Vector3 direction = point - pivot;
return pivot + (rotation * direction);
}
private static void Rotate(
Quaternion orientation,
ref Vector3 localFrontTopLeft,
ref Vector3 localFrontTopRight,
ref Vector3 localFrontBottomLeft,
ref Vector3 localFrontBottomRight
)
{
localFrontTopLeft = RotatePointAroundPivot(localFrontTopLeft, Vector3.zero, orientation);
localFrontTopRight = RotatePointAroundPivot(localFrontTopRight, Vector3.zero, orientation);
localFrontBottomLeft = RotatePointAroundPivot(localFrontBottomLeft, Vector3.zero, orientation);
localFrontBottomRight = RotatePointAroundPivot(localFrontBottomRight, Vector3.zero, orientation);
}
}

160
X10D.Unity/src/Box2D.cs Normal file
View File

@ -0,0 +1,160 @@
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);
}
}

View File

@ -0,0 +1,169 @@
using UnityEngine;
namespace X10D.Unity;
public static partial class DebugEx
{
/// <summary>
/// Draws a box.
/// </summary>
/// <param name="center">The center point.</param>
/// <param name="halfExtents">The extents of the box, halved.</param>
public static void DrawBox(Vector3 center, Vector3 halfExtents)
{
DrawBox(center, halfExtents, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a box with the specified orientation.
/// </summary>
/// <param name="center">The center point.</param>
/// <param name="halfExtents">The extents of the box, halved.</param>
/// <param name="orientation">The orientation of the box.</param>
public static void DrawBox(Vector3 center, Vector3 halfExtents, Quaternion orientation)
{
DrawBox(new Box(center, halfExtents, orientation), Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a box 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 DrawBox(Vector3 center, Vector3 halfExtents, in Color color)
{
DrawBox(center, halfExtents, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a box with the specified orientation and color.
/// </summary>
/// <param name="center">The center point.</param>
/// <param name="halfExtents">The extents of the box, halved.</param>
/// <param name="orientation">The orientation of the box.</param>
/// <param name="color">The color of the box.</param>
public static void DrawBox(Vector3 center, Vector3 halfExtents, Quaternion orientation, in Color color)
{
DrawBox(new Box(center, halfExtents, orientation), color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a box 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 DrawBox(Vector3 center, Vector3 halfExtents, in Color color, float duration)
{
DrawBox(center, halfExtents, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a box with the specified orientation, color, and duration.
/// </summary>
/// <param name="center">The center point.</param>
/// <param name="halfExtents">The extents of the box, halved.</param>
/// <param name="orientation">The orientation 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 DrawBox(Vector3 center, Vector3 halfExtents, Quaternion orientation, in Color color, float duration)
{
DrawBox(new Box(center, halfExtents, orientation), color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a box 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 DrawBox(Vector3 center, Vector3 halfExtents, in Color color, float duration, bool depthTest)
{
DrawBox(new Box(center, halfExtents), color, duration, depthTest);
}
/// <summary>
/// Draws a box with the specified orientation, color, and duration.
/// </summary>
/// <param name="center">The center point.</param>
/// <param name="halfExtents">The extents of the box, halved.</param>
/// <param name="orientation">The orientation 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 DrawBox(Vector3 center, Vector3 halfExtents, Quaternion orientation, in Color color, float duration, bool depthTest)
{
DrawBox(new Box(center, halfExtents, orientation), color, duration, depthTest);
}
/// <summary>
/// Draws a box 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 DrawBox(Box box, in Color color)
{
DrawBox(box, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a box 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 DrawBox(Box box, in Color color, float duration)
{
DrawBox(box, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a box 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 DrawBox(Box box, in Color color, float duration, bool depthTest)
{
Debug.DrawLine(box.FrontTopLeft, box.FrontTopRight, color, duration, depthTest);
Debug.DrawLine(box.FrontTopRight, box.FrontBottomRight, color, duration, depthTest);
Debug.DrawLine(box.FrontBottomRight, box.FrontBottomLeft, color, duration, depthTest);
Debug.DrawLine(box.FrontBottomLeft, box.FrontTopLeft, color, duration, depthTest);
Debug.DrawLine(box.BackTopLeft, box.BackTopRight, color, duration, depthTest);
Debug.DrawLine(box.BackTopRight, box.BackBottomRight, color, duration, depthTest);
Debug.DrawLine(box.BackBottomRight, box.BackBottomLeft, color, duration, depthTest);
Debug.DrawLine(box.BackBottomLeft, box.BackTopLeft, color, duration, depthTest);
Debug.DrawLine(box.FrontTopLeft, box.BackTopLeft, color, duration, depthTest);
Debug.DrawLine(box.FrontTopRight, box.BackTopRight, color, duration, depthTest);
Debug.DrawLine(box.FrontBottomRight, box.BackBottomRight, color, duration, depthTest);
Debug.DrawLine(box.FrontBottomLeft, box.BackBottomLeft, color, duration, depthTest);
}
}

View File

@ -0,0 +1,333 @@
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);
}
}

View File

@ -0,0 +1,331 @@
using UnityEngine;
using X10D.Drawing;
using X10D.Numerics;
using X10D.Unity.Numerics;
using Quaternion = System.Numerics.Quaternion;
namespace X10D.Unity;
public static partial class DebugEx
{
/// <summary>
/// Draws a circle with the specified color.
/// </summary>
/// <param name="center">The center point of the circle.</param>
/// <param name="radius">The radius of the circle.</param>
/// <param name="sides">The number of sides to generate.</param>
public static void DrawCircle(Vector2 center, float radius, int sides)
{
DrawCircle(center, radius, sides, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color.
/// </summary>
/// <param name="center">The center point of the circle.</param>
/// <param name="radius">The radius of the circle.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the circle.</param>
public static void DrawCircle(Vector2 center, float radius, int sides, in Color color)
{
DrawCircle(center, radius, sides, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color and duration.
/// </summary>
/// <param name="center">The center point of the circle.</param>
/// <param name="radius">The radius of the circle.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the circle.</param>
/// <param name="duration">
/// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame.
/// </param>
public static void DrawCircle(Vector2 center, float radius, int sides, in Color color, float duration)
{
DrawCircle(center, radius, sides, Vector2.zero, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color and duration.
/// </summary>
/// <param name="center">The center point of the circle.</param>
/// <param name="radius">The radius of the circle.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the circle.</param>
/// <param name="duration">
/// The duration of the circle's visibility, in seconds. If 0 is passed, the circle 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 circle be obscured by objects closer to the camera.
/// </param>
public static void DrawCircle(Vector2 center, float radius, int sides, in Color color, float duration, bool depthTest)
{
DrawCircle(center, radius, sides, Vector2.zero, color, duration, depthTest);
}
/// <summary>
/// Draws a circle.
/// </summary>
/// <param name="center">The center point of the circle.</param>
/// <param name="radius">The radius of the circle.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the circle.</param>
/// <param name="color">The color of the circle.</param>
/// <param name="duration">
/// The duration of the circle's visibility, in seconds. If 0 is passed, the circle 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 circle be obscured by objects closer to the camera.
/// </param>
public static void DrawCircle(Vector2 center, float radius, int sides, in Vector3 offset, in Color color, float duration,
bool depthTest)
{
DrawCircle(new CircleF(center.ToSystemVector(), radius), sides, offset, color, duration, depthTest);
}
/// <summary>
/// Draws a circle with the specified color.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
public static void DrawCircle(in Circle circle, int sides)
{
DrawCircle((CircleF)circle, sides, Vector2.zero, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the circle.</param>
public static void DrawCircle(in Circle circle, int sides, in Vector3 offset)
{
DrawCircle((CircleF)circle, sides, offset, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the circle.</param>
public static void DrawCircle(in Circle circle, int sides, in Color color)
{
DrawCircle((CircleF)circle, sides, Vector2.zero, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the circle.</param>
/// <param name="color">The color of the circle.</param>
public static void DrawCircle(in Circle circle, int sides, in Vector3 offset, in Color color)
{
DrawCircle((CircleF)circle, sides, offset, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color and duration.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the circle.</param>
/// <param name="duration">
/// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame.
/// </param>
public static void DrawCircle(in Circle circle, int sides, in Color color, float duration)
{
DrawCircle((CircleF)circle, sides, Vector2.zero, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color and duration.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the circle.</param>
/// <param name="color">The color of the circle.</param>
/// <param name="duration">
/// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame.
/// </param>
public static void DrawCircle(in Circle circle, int sides, in Vector3 offset, in Color color, float duration)
{
DrawCircle((CircleF)circle, sides, offset, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color and duration.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the circle.</param>
/// <param name="duration">
/// The duration of the circle's visibility, in seconds. If 0 is passed, the circle 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 circle be obscured by objects closer to the camera.
/// </param>
public static void DrawCircle(in Circle circle, int sides, in Color color, float duration, bool depthTest)
{
DrawCircle((CircleF)circle, sides, Vector2.zero, color, duration, depthTest);
}
/// <summary>
/// Draws a circle.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the circle.</param>
/// <param name="color">The color of the circle.</param>
/// <param name="duration">
/// The duration of the circle's visibility, in seconds. If 0 is passed, the circle 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 circle be obscured by objects closer to the camera.
/// </param>
public static void DrawCircle(in Circle circle, int sides, in Vector3 offset, in Color color, float duration, bool depthTest)
{
DrawCircle((CircleF)circle, sides, offset, color, duration, depthTest);
}
/// <summary>
/// Draws a circle with the specified color.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
public static void DrawCircle(in CircleF circle, int sides)
{
DrawCircle(circle, sides, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the circle.</param>
public static void DrawCircle(in CircleF circle, int sides, in Vector3 offset)
{
DrawCircle(circle, sides, offset, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the circle.</param>
public static void DrawCircle(in CircleF circle, int sides, in Color color)
{
DrawCircle(circle, sides, Vector2.zero, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the circle.</param>
/// <param name="color">The color of the circle.</param>
public static void DrawCircle(in CircleF circle, int sides, in Vector3 offset, in Color color)
{
DrawCircle(circle, sides, offset, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color and duration.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the circle.</param>
/// <param name="duration">
/// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame.
/// </param>
public static void DrawCircle(in CircleF circle, int sides, in Color color, float duration)
{
DrawCircle(circle, sides, Vector2.zero, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color and duration.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the circle.</param>
/// <param name="color">The color of the circle.</param>
/// <param name="duration">
/// The duration of the circle's visibility, in seconds. If 0 is passed, the circle is visible for a single frame.
/// </param>
public static void DrawCircle(in CircleF circle, int sides, in Vector3 offset, in Color color, float duration)
{
DrawCircle(circle, sides, offset, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a circle with the specified color and duration.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the circle.</param>
/// <param name="duration">
/// The duration of the circle's visibility, in seconds. If 0 is passed, the circle 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 circle be obscured by objects closer to the camera.
/// </param>
public static void DrawCircle(in CircleF circle, int sides, in Color color, float duration, bool depthTest)
{
DrawCircle(circle, sides, Vector2.zero, color, duration, depthTest);
}
/// <summary>
/// Draws a circle.
/// </summary>
/// <param name="circle">The circle to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the circle.</param>
/// <param name="color">The color of the circle.</param>
/// <param name="duration">
/// The duration of the circle's visibility, in seconds. If 0 is passed, the circle 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 circle be obscured by objects closer to the camera.
/// </param>
public static void DrawCircle(in CircleF circle, int sides, in Vector3 offset, in Color color, float duration, bool depthTest)
{
DrawPolyhedron(CreateCircle(circle.Radius, sides, Vector3.zero), offset, color, duration, depthTest);
}
private static Polyhedron CreateCircle(float radius, int sides, in Vector3 axis)
{
const float max = 2.0f * MathF.PI;
float step = max / sides;
var points = new List<System.Numerics.Vector3>();
for (var theta = 0f; theta < max; theta += step)
{
float x = radius * MathF.Cos(theta);
float y = radius * MathF.Sin(theta);
var vector = new System.Numerics.Vector3(x, y, 0);
if (axis != Vector3.zero)
{
vector = Quaternion.CreateFromAxisAngle(axis.ToSystemVector(), MathF.PI / 2.0f).Multiply(vector);
}
points.Add(vector);
}
return new Polyhedron(points);
}
}

View File

@ -0,0 +1,406 @@
using UnityEngine;
using X10D.Drawing;
namespace X10D.Unity;
public static partial class DebugEx
{
/// <summary>
/// Draws an ellipse with the specified color.
/// </summary>
/// <param name="center">The center point of the ellipse.</param>
/// <param name="radius">The radius of the ellipse.</param>
/// <param name="sides">The number of sides to generate.</param>
public static void DrawEllipse(Vector2 center, Vector2 radius, int sides)
{
DrawEllipse(center, radius.x, radius.y, sides, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color.
/// </summary>
/// <param name="center">The center point of the ellipse.</param>
/// <param name="radius">The radius of the ellipse.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the ellipse.</param>
public static void DrawEllipse(Vector2 center, Vector2 radius, int sides, in Color color)
{
DrawEllipse(center, radius.x, radius.y, sides, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color and duration.
/// </summary>
/// <param name="center">The center point of the ellipse.</param>
/// <param name="radius">The radius of the ellipse.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the ellipse.</param>
/// <param name="duration">
/// The duration of the ellipse's visibility, in seconds. If 0 is passed, the ellipse is visible for a single frame.
/// </param>
public static void DrawEllipse(Vector2 center, Vector2 radius, int sides, in Color color, float duration)
{
DrawEllipse(center, radius.x, radius.y, sides, Vector2.zero, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color and duration.
/// </summary>
/// <param name="center">The center point of the ellipse.</param>
/// <param name="radius">The radius of the ellipse.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the ellipse.</param>
/// <param name="duration">
/// The duration of the ellipse's visibility, in seconds. If 0 is passed, the ellipse 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 ellipse be obscured by objects closer to the camera.
/// </param>
public static void DrawEllipse(Vector2 center, Vector2 radius, int sides, in Color color, float duration, bool depthTest)
{
DrawEllipse(center, radius.x, radius.y, sides, Vector2.zero, color, duration, depthTest);
}
/// <summary>
/// Draws an ellipse.
/// </summary>
/// <param name="center">The center point of the ellipse.</param>
/// <param name="radius">The radius of the ellipse.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the ellipse.</param>
/// <param name="color">The color of the ellipse.</param>
/// <param name="duration">
/// The duration of the ellipse's visibility, in seconds. If 0 is passed, the ellipse 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 ellipse be obscured by objects closer to the camera.
/// </param>
public static void DrawEllipse(Vector2 center, Vector2 radius, int sides, Vector2 offset, in Color color, float duration,
bool depthTest)
{
DrawEllipse(new EllipseF(center.x, center.y, radius.x, radius.y), sides, offset, color, duration, depthTest);
}
/// <summary>
/// Draws an ellipse with the specified color.
/// </summary>
/// <param name="center">The center point of the ellipse.</param>
/// <param name="radiusX">The horizontal radius of the ellipse.</param>
/// <param name="radiusY">The vertical radius of the ellipse.</param>
/// <param name="sides">The number of sides to generate.</param>
public static void DrawEllipse(Vector2 center, float radiusX, float radiusY, int sides)
{
DrawEllipse(center, radiusX, radiusY, sides, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color.
/// </summary>
/// <param name="center">The center point of the ellipse.</param>
/// <param name="radiusX">The horizontal radius of the ellipse.</param>
/// <param name="radiusY">The vertical radius of the ellipse.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the ellipse.</param>
public static void DrawEllipse(Vector2 center, float radiusX, float radiusY, int sides, in Color color)
{
DrawEllipse(center, radiusX, radiusY, sides, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color and duration.
/// </summary>
/// <param name="center">The center point of the ellipse.</param>
/// <param name="radiusX">The horizontal radius of the ellipse.</param>
/// <param name="radiusY">The vertical radius of the ellipse.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the ellipse.</param>
/// <param name="duration">
/// The duration of the ellipse's visibility, in seconds. If 0 is passed, the ellipse is visible for a single frame.
/// </param>
public static void DrawEllipse(Vector2 center, float radiusX, float radiusY, int sides, in Color color, float duration)
{
DrawEllipse(center, radiusX, radiusY, sides, Vector2.zero, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color and duration.
/// </summary>
/// <param name="center">The center point of the ellipse.</param>
/// <param name="radiusX">The horizontal radius of the ellipse.</param>
/// <param name="radiusY">The vertical radius of the ellipse.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the ellipse.</param>
/// <param name="duration">
/// The duration of the ellipse's visibility, in seconds. If 0 is passed, the ellipse 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 ellipse be obscured by objects closer to the camera.
/// </param>
public static void DrawEllipse(Vector2 center, float radiusX, float radiusY, int sides, in Color color, float duration,
bool depthTest)
{
DrawEllipse(center, radiusX, radiusY, sides, Vector2.zero, color, duration, depthTest);
}
/// <summary>
/// Draws an ellipse.
/// </summary>
/// <param name="center">The center point of the ellipse.</param>
/// <param name="radiusX">The horizontal radius of the ellipse.</param>
/// <param name="radiusY">The vertical radius of the ellipse.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the ellipse.</param>
/// <param name="color">The color of the ellipse.</param>
/// <param name="duration">
/// The duration of the ellipse's visibility, in seconds. If 0 is passed, the ellipse 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 ellipse be obscured by objects closer to the camera.
/// </param>
public static void DrawEllipse(Vector2 center, float radiusX, float radiusY, int sides, Vector2 offset, in Color color,
float duration, bool depthTest)
{
DrawEllipse(new EllipseF(center.x, center.y, radiusX, radiusY), sides, offset, color, duration, depthTest);
}
/// <summary>
/// Draws an ellipse with the specified color.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
public static void DrawEllipse(Ellipse ellipse, int sides)
{
DrawEllipse((EllipseF)ellipse, sides, Vector2.zero, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the ellipse.</param>
public static void DrawEllipse(Ellipse ellipse, int sides, Vector2 offset)
{
DrawEllipse((EllipseF)ellipse, sides, offset, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the ellipse.</param>
public static void DrawEllipse(Ellipse ellipse, int sides, in Color color)
{
DrawEllipse((EllipseF)ellipse, sides, Vector2.zero, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the ellipse.</param>
/// <param name="color">The color of the ellipse.</param>
public static void DrawEllipse(Ellipse ellipse, int sides, Vector2 offset, in Color color)
{
DrawEllipse((EllipseF)ellipse, sides, offset, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color and duration.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the ellipse.</param>
/// <param name="duration">
/// The duration of the ellipse's visibility, in seconds. If 0 is passed, the ellipse is visible for a single frame.
/// </param>
public static void DrawEllipse(Ellipse ellipse, int sides, in Color color, float duration)
{
DrawEllipse((EllipseF)ellipse, sides, Vector2.zero, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color and duration.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the ellipse.</param>
/// <param name="color">The color of the ellipse.</param>
/// <param name="duration">
/// The duration of the ellipse's visibility, in seconds. If 0 is passed, the ellipse is visible for a single frame.
/// </param>
public static void DrawEllipse(Ellipse ellipse, int sides, Vector2 offset, in Color color, float duration)
{
DrawEllipse((EllipseF)ellipse, sides, offset, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color and duration.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the ellipse.</param>
/// <param name="duration">
/// The duration of the ellipse's visibility, in seconds. If 0 is passed, the ellipse 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 ellipse be obscured by objects closer to the camera.
/// </param>
public static void DrawEllipse(Ellipse ellipse, int sides, in Color color, float duration, bool depthTest)
{
DrawEllipse((EllipseF)ellipse, sides, Vector2.zero, color, duration, depthTest);
}
/// <summary>
/// Draws an ellipse.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the ellipse.</param>
/// <param name="color">The color of the ellipse.</param>
/// <param name="duration">
/// The duration of the ellipse's visibility, in seconds. If 0 is passed, the ellipse 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 ellipse be obscured by objects closer to the camera.
/// </param>
public static void DrawEllipse(Ellipse ellipse, int sides, Vector2 offset, in Color color, float duration, bool depthTest)
{
DrawEllipse((EllipseF)ellipse, sides, offset, color, duration, depthTest);
}
/// <summary>
/// Draws an ellipse with the specified color.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
public static void DrawEllipse(EllipseF ellipse, int sides)
{
DrawEllipse(ellipse, sides, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the ellipse.</param>
public static void DrawEllipse(EllipseF ellipse, int sides, Vector2 offset)
{
DrawEllipse(ellipse, sides, offset, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the ellipse.</param>
public static void DrawEllipse(EllipseF ellipse, int sides, in Color color)
{
DrawEllipse(ellipse, sides, Vector2.zero, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the ellipse.</param>
/// <param name="color">The color of the ellipse.</param>
public static void DrawEllipse(EllipseF ellipse, int sides, Vector2 offset, in Color color)
{
DrawEllipse(ellipse, sides, offset, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color and duration.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the ellipse.</param>
/// <param name="duration">
/// The duration of the ellipse's visibility, in seconds. If 0 is passed, the ellipse is visible for a single frame.
/// </param>
public static void DrawEllipse(EllipseF ellipse, int sides, in Color color, float duration)
{
DrawEllipse(ellipse, sides, Vector2.zero, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color and duration.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the ellipse.</param>
/// <param name="color">The color of the ellipse.</param>
/// <param name="duration">
/// The duration of the ellipse's visibility, in seconds. If 0 is passed, the ellipse is visible for a single frame.
/// </param>
public static void DrawEllipse(EllipseF ellipse, int sides, Vector2 offset, in Color color, float duration)
{
DrawEllipse(ellipse, sides, offset, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws an ellipse with the specified color and duration.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the ellipse.</param>
/// <param name="duration">
/// The duration of the ellipse's visibility, in seconds. If 0 is passed, the ellipse 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 ellipse be obscured by objects closer to the camera.
/// </param>
public static void DrawEllipse(EllipseF ellipse, int sides, in Color color, float duration, bool depthTest)
{
DrawEllipse(ellipse, sides, Vector2.zero, color, duration, depthTest);
}
/// <summary>
/// Draws an ellipse.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the ellipse.</param>
/// <param name="color">The color of the ellipse.</param>
/// <param name="duration">
/// The duration of the ellipse's visibility, in seconds. If 0 is passed, the ellipse 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 ellipse be obscured by objects closer to the camera.
/// </param>
public static void DrawEllipse(EllipseF ellipse, int sides, Vector2 offset, in Color color, float duration, bool depthTest)
{
DrawPolygon(CreateEllipse(ellipse.HorizontalRadius, ellipse.VerticalRadius, sides), offset, color, duration, depthTest);
}
private static PolygonF CreateEllipse(float radiusX, float radiusY, int sides)
{
const float max = 2.0f * MathF.PI;
float step = max / sides;
var points = new List<System.Numerics.Vector2>();
for (var theta = 0f; theta < max; theta += step)
{
float x = radiusX * MathF.Cos(theta);
float y = radiusY * MathF.Sin(theta);
points.Add(new System.Numerics.Vector2(x, y));
}
return new PolygonF(points);
}
}

View File

@ -0,0 +1,209 @@
using UnityEngine;
using X10D.Drawing;
using X10D.Unity.Drawing;
using X10D.Unity.Numerics;
namespace X10D.Unity;
public static partial class DebugEx
{
/// <summary>
/// Draws a line between start and end points.
/// </summary>
/// <param name="start">The starting point.</param>
/// <param name="end">The ending point.</param>
public static void DrawLine(Vector3 start, Vector3 end)
{
DrawLine(start, end, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a line between start and end points, with the specified color.
/// </summary>
/// <param name="start">The starting point.</param>
/// <param name="end">The ending point.</param>
/// <param name="color">The color of the line.</param>
public static void DrawLine(Vector3 start, Vector3 end, in Color color)
{
DrawLine(start, end, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a line between start and end points, with the specified color.
/// </summary>
/// <param name="start">The starting point.</param>
/// <param name="end">The ending point.</param>
/// <param name="color">The color of the line.</param>
/// <param name="duration">
/// The duration of the line's visibility, in seconds. If 0 is passed, the line is visible for a single frame.
/// </param>
public static void DrawLine(Vector3 start, Vector3 end, in Color color, float duration)
{
DrawLine(start, end, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a line between start and end points, with the specified color.
/// </summary>
/// <param name="start">The starting point.</param>
/// <param name="end">The ending point.</param>
/// <param name="color">The color of the line.</param>
/// <param name="duration">
/// The duration of the line's visibility, in seconds. If 0 is passed, the line 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 line be obscured by objects closer to the camera.
/// </param>
public static void DrawLine(Vector3 start, Vector3 end, in Color color, float duration, bool depthTest)
{
Debug.DrawLine(start, end, color, duration, depthTest);
}
/// <summary>
/// Draws a line between start and end points.
/// </summary>
/// <param name="line">The line to draw.</param>
public static void DrawLine(Line line)
{
DrawLine(line, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a line between start and end points, with the specified color.
/// </summary>
/// <param name="line">The line to draw.</param>
/// <param name="color">The color of the line.</param>
public static void DrawLine(Line line, in Color color)
{
DrawLine(line, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a line between start and end points, with the specified color.
/// </summary>
/// <param name="line">The line to draw.</param>
/// <param name="color">The color of the line.</param>
/// <param name="duration">
/// The duration of the line's visibility, in seconds. If 0 is passed, the line is visible for a single frame.
/// </param>
public static void DrawLine(Line line, in Color color, float duration)
{
DrawLine(line, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a line between start and end points, with the specified color.
/// </summary>
/// <param name="line">The line to draw.</param>
/// <param name="color">The color of the line.</param>
/// <param name="duration">
/// The duration of the line's visibility, in seconds. If 0 is passed, the line 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 line be obscured by objects closer to the camera.
/// </param>
public static void DrawLine(Line line, in Color color, float duration, bool depthTest)
{
Debug.DrawLine(line.Start.ToUnityVector2(), line.End.ToUnityVector2(), color, duration, depthTest);
}
/// <summary>
/// Draws a line between start and end points.
/// </summary>
/// <param name="line">The line to draw.</param>
public static void DrawLine(LineF line)
{
DrawLine(line, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a line between start and end points, with the specified color.
/// </summary>
/// <param name="line">The line to draw.</param>
/// <param name="color">The color of the line.</param>
public static void DrawLine(LineF line, in Color color)
{
DrawLine(line, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a line between start and end points, with the specified color.
/// </summary>
/// <param name="line">The line to draw.</param>
/// <param name="color">The color of the line.</param>
/// <param name="duration">
/// The duration of the line's visibility, in seconds. If 0 is passed, the line is visible for a single frame.
/// </param>
public static void DrawLine(LineF line, in Color color, float duration)
{
DrawLine(line, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a line between start and end points, with the specified color.
/// </summary>
/// <param name="line">The line to draw.</param>
/// <param name="color">The color of the line.</param>
/// <param name="duration">
/// The duration of the line's visibility, in seconds. If 0 is passed, the line 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 line be obscured by objects closer to the camera.
/// </param>
public static void DrawLine(LineF line, in Color color, float duration, bool depthTest)
{
Debug.DrawLine(line.Start.ToUnityVector2(), line.End.ToUnityVector2(), color, duration, depthTest);
}
/// <summary>
/// Draws a line between start and end points.
/// </summary>
/// <param name="line">The line to draw.</param>
public static void DrawLine(Line3D line)
{
DrawLine(line, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a line between start and end points, with the specified color.
/// </summary>
/// <param name="line">The line to draw.</param>
/// <param name="color">The color of the line.</param>
public static void DrawLine(Line3D line, in Color color)
{
DrawLine(line, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a line between start and end points, with the specified color.
/// </summary>
/// <param name="line">The line to draw.</param>
/// <param name="color">The color of the line.</param>
/// <param name="duration">
/// The duration of the line's visibility, in seconds. If 0 is passed, the line is visible for a single frame.
/// </param>
public static void DrawLine(Line3D line, in Color color, float duration)
{
DrawLine(line, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a line between start and end points, with the specified color.
/// </summary>
/// <param name="line">The line to draw.</param>
/// <param name="color">The color of the line.</param>
/// <param name="duration">
/// The duration of the line's visibility, in seconds. If 0 is passed, the line 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 line be obscured by objects closer to the camera.
/// </param>
public static void DrawLine(Line3D line, in Color color, float duration, bool depthTest)
{
Debug.DrawLine(line.Start.ToUnityVector(), line.End.ToUnityVector(), color, duration, depthTest);
}
}

View File

@ -0,0 +1,226 @@
using UnityEngine;
using X10D.Drawing;
using X10D.Unity.Drawing;
using PointF = System.Drawing.PointF;
namespace X10D.Unity;
public static partial class DebugEx
{
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
public static void DrawPolygon(Polygon polygon)
{
DrawPolygon((PolygonF)polygon, Vector2.zero, Color.white, DefaultDrawDuration, true);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
/// <param name="offset">The drawing offset of the polygon.</param>
public static void DrawPolygon(Polygon polygon, in Vector3 offset)
{
DrawPolygon((PolygonF)polygon, offset, Color.white, DefaultDrawDuration, true);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
/// <param name="color">The color to use for drawing.</param>
public static void DrawPolygon(Polygon polygon, in Color color)
{
DrawPolygon((PolygonF)polygon, Vector2.zero, color, DefaultDrawDuration, true);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
/// <param name="offset">The drawing offset of the polygon.</param>
/// <param name="color">The color to use for drawing.</param>
public static void DrawPolygon(Polygon polygon, in Vector3 offset, in Color color)
{
DrawPolygon((PolygonF)polygon, offset, color, DefaultDrawDuration, true);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
/// <param name="color">The color to use for drawing.</param>
/// <param name="duration">
/// The duration of the polygon's visibility, in seconds. If 0 is passed, the polygon is visible for a single frame.
/// </param>
public static void DrawPolygon(Polygon polygon, in Color color, float duration)
{
DrawPolygon((PolygonF)polygon, Vector2.zero, color, duration, true);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
/// <param name="offset">The drawing offset of the polygon.</param>
/// <param name="color">The color to use for drawing.</param>
/// <param name="duration">
/// The duration of the polygon's visibility, in seconds. If 0 is passed, the polygon is visible for a single frame.
/// </param>
public static void DrawPolygon(Polygon polygon, in Vector3 offset, in Color color, float duration)
{
DrawPolygon((PolygonF)polygon, offset, color, duration, true);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
/// <param name="color">The color to use for drawing.</param>
/// <param name="duration">
/// The duration of the polygon's visibility, in seconds. If 0 is passed, the polygon is visible for a single frame.
/// </param>
/// <param name="depthTest">
/// <see langword="true" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
/// <see langword="true" /> will have the box be obscured by objects closer to the camera.
/// </param>
public static void DrawPolygon(Polygon polygon, in Color color, float duration, bool depthTest)
{
DrawPolygon((PolygonF)polygon, Vector2.zero, color, duration, depthTest);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
/// <param name="offset">The drawing offset of the polygon.</param>
/// <param name="color">The color to use for drawing.</param>
/// <param name="duration">
/// The duration of the polygon's visibility, in seconds. If 0 is passed, the polygon is visible for a single frame.
/// </param>
/// <param name="depthTest">
/// <see langword="true" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
/// <see langword="true" /> will have the box be obscured by objects closer to the camera.
/// </param>
public static void DrawPolygon(Polygon polygon, in Vector3 offset, in Color color, float duration, bool depthTest)
{
DrawPolygon((PolygonF)polygon, offset, color, duration, depthTest);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
public static void DrawPolygon(PolygonF polygon)
{
DrawPolygon(polygon, Vector2.zero, Color.white, DefaultDrawDuration, true);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
/// <param name="offset">The drawing offset of the polygon.</param>
public static void DrawPolygon(PolygonF polygon, in Vector3 offset)
{
DrawPolygon(polygon, offset, Color.white, DefaultDrawDuration, true);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
/// <param name="color">The color to use for drawing.</param>
public static void DrawPolygon(PolygonF polygon, in Color color)
{
DrawPolygon(polygon, Vector2.zero, color, DefaultDrawDuration, true);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
/// <param name="offset">The drawing offset of the polygon.</param>
/// <param name="color">The color to use for drawing.</param>
public static void DrawPolygon(PolygonF polygon, in Vector3 offset, in Color color)
{
DrawPolygon(polygon, offset, color, DefaultDrawDuration, true);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
/// <param name="color">The color to use for drawing.</param>
/// <param name="duration">
/// The duration of the polygon's visibility, in seconds. If 0 is passed, the polygon is visible for a single frame.
/// </param>
public static void DrawPolygon(PolygonF polygon, in Color color, float duration)
{
DrawPolygon(polygon, Vector2.zero, color, duration, true);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
/// <param name="offset">The drawing offset of the polygon.</param>
/// <param name="color">The color to use for drawing.</param>
/// <param name="duration">
/// The duration of the polygon's visibility, in seconds. If 0 is passed, the polygon is visible for a single frame.
/// </param>
public static void DrawPolygon(PolygonF polygon, in Vector3 offset, in Color color, float duration)
{
DrawPolygon(polygon, offset, color, duration, true);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
/// <param name="color">The color to use for drawing.</param>
/// <param name="duration">
/// The duration of the polygon's visibility, in seconds. If 0 is passed, the polygon is visible for a single frame.
/// </param>
/// <param name="depthTest">
/// <see langword="true" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
/// <see langword="true" /> will have the box be obscured by objects closer to the camera.
/// </param>
public static void DrawPolygon(PolygonF polygon, in Color color, float duration, bool depthTest)
{
DrawPolygon(polygon, Vector2.zero, color, duration, depthTest);
}
/// <summary>
/// Draws a polygon.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
/// <param name="offset">The drawing offset of the polygon.</param>
/// <param name="color">The color to use for drawing.</param>
/// <param name="duration">
/// The duration of the polygon's visibility, in seconds. If 0 is passed, the polygon is visible for a single frame.
/// </param>
/// <param name="depthTest">
/// <see langword="true" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
/// <see langword="true" /> will have the box be obscured by objects closer to the camera.
/// </param>
public static void DrawPolygon(PolygonF polygon, in Vector3 offset, in Color color, float duration, bool depthTest)
{
IReadOnlyList<PointF> points = polygon.Vertices;
if (points.Count < 2)
{
return;
}
for (var i = 0; i < points.Count; i++)
{
int j = (i + 1) % points.Count;
Vector3 start = (Vector3)points[i].ToUnityVector2() + offset;
Vector3 end = (Vector3)points[j].ToUnityVector2() + offset;
DrawLine(start, end, color, duration, depthTest);
}
}
}

View File

@ -0,0 +1,123 @@
using UnityEngine;
using X10D.Drawing;
using X10D.Unity.Numerics;
namespace X10D.Unity;
public static partial class DebugEx
{
/// <summary>
/// Draws a polyhedron.
/// </summary>
/// <param name="polyhedron">The polyhedron to draw.</param>
public static void DrawPolyhedron(Polyhedron polyhedron)
{
DrawPolyhedron(polyhedron, Vector2.zero, Color.white, DefaultDrawDuration, true);
}
/// <summary>
/// Draws a polyhedron.
/// </summary>
/// <param name="polyhedron">The polyhedron to draw.</param>
/// <param name="offset">The drawing offset of the polyhedron.</param>
public static void DrawPolyhedron(Polyhedron polyhedron, in Vector3 offset)
{
DrawPolyhedron(polyhedron, offset, Color.white, DefaultDrawDuration, true);
}
/// <summary>
/// Draws a polyhedron.
/// </summary>
/// <param name="polyhedron">The polyhedron to draw.</param>
/// <param name="color">The color to use for drawing.</param>
public static void DrawPolyhedron(Polyhedron polyhedron, in Color color)
{
DrawPolyhedron(polyhedron, Vector2.zero, color, DefaultDrawDuration, true);
}
/// <summary>
/// Draws a polyhedron.
/// </summary>
/// <param name="polyhedron">The polyhedron to draw.</param>
/// <param name="offset">The drawing offset of the polyhedron.</param>
/// <param name="color">The color to use for drawing.</param>
public static void DrawPolyhedron(Polyhedron polyhedron, in Vector3 offset, in Color color)
{
DrawPolyhedron(polyhedron, offset, color, DefaultDrawDuration, true);
}
/// <summary>
/// Draws a polyhedron.
/// </summary>
/// <param name="polyhedron">The polyhedron to draw.</param>
/// <param name="color">The color to use for drawing.</param>
/// <param name="duration">
/// The duration of the polyhedron's visibility, in seconds. If 0 is passed, the polyhedron is visible for a single frame.
/// </param>
public static void DrawPolyhedron(Polyhedron polyhedron, in Color color, float duration)
{
DrawPolyhedron(polyhedron, Vector2.zero, color, duration, true);
}
/// <summary>
/// Draws a polyhedron.
/// </summary>
/// <param name="polyhedron">The polyhedron to draw.</param>
/// <param name="offset">The drawing offset of the polyhedron.</param>
/// <param name="color">The color to use for drawing.</param>
/// <param name="duration">
/// The duration of the polyhedron's visibility, in seconds. If 0 is passed, the polyhedron is visible for a single frame.
/// </param>
public static void DrawPolyhedron(Polyhedron polyhedron, in Vector3 offset, in Color color, float duration)
{
DrawPolyhedron(polyhedron, offset, color, duration, true);
}
/// <summary>
/// Draws a polyhedron.
/// </summary>
/// <param name="polyhedron">The polyhedron to draw.</param>
/// <param name="color">The color to use for drawing.</param>
/// <param name="duration">
/// The duration of the polyhedron's visibility, in seconds. If 0 is passed, the polyhedron is visible for a single frame.
/// </param>
/// <param name="depthTest">
/// <see langword="true" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
/// <see langword="true" /> will have the box be obscured by objects closer to the camera.
/// </param>
public static void DrawPolyhedron(Polyhedron polyhedron, in Color color, float duration, bool depthTest)
{
DrawPolyhedron(polyhedron, Vector2.zero, color, duration, depthTest);
}
/// <summary>
/// Draws a polyhedron.
/// </summary>
/// <param name="polyhedron">The polyhedron to draw.</param>
/// <param name="offset">The drawing offset of the polyhedron.</param>
/// <param name="color">The color to use for drawing.</param>
/// <param name="duration">
/// The duration of the polyhedron's visibility, in seconds. If 0 is passed, the polyhedron is visible for a single frame.
/// </param>
/// <param name="depthTest">
/// <see langword="true" /> if depth test should be applied; otherwise, <see langword="false" />. Passing
/// <see langword="true" /> will have the box be obscured by objects closer to the camera.
/// </param>
public static void DrawPolyhedron(Polyhedron polyhedron, in Vector3 offset, in Color color, float duration, bool depthTest)
{
IReadOnlyList<System.Numerics.Vector3> points = polyhedron.Vertices;
if (points.Count < 2)
{
return;
}
for (var i = 0; i < points.Count; i++)
{
int j = (i + 1) % points.Count;
Vector3 start = points[i].ToUnityVector() + offset;
Vector3 end = points[j].ToUnityVector() + offset;
DrawLine(start, end, color, duration, depthTest);
}
}
}

View File

@ -0,0 +1,108 @@
using UnityEngine;
namespace X10D.Unity;
public static partial class DebugEx
{
/// <summary>
/// Draws a ray.
/// </summary>
/// <param name="ray">The ray to draw.</param>
public static void DrawRay(Ray ray)
{
DrawRay(ray, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a ray.
/// </summary>
/// <param name="ray">The ray to draw.</param>
/// <param name="color">The color of the line.</param>
public static void DrawRay(Ray ray, in Color color)
{
DrawRay(ray, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a ray.
/// </summary>
/// <param name="ray">The ray to draw.</param>
/// <param name="color">The color of the line.</param>
/// <param name="duration">
/// The duration of the line's visibility, in seconds. If 0 is passed, the line is visible for a single frame.
/// </param>
public static void DrawRay(Ray ray, in Color color, float duration)
{
DrawRay(ray, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a ray.
/// </summary>
/// <param name="ray">The ray to draw.</param>
/// <param name="color">The color of the line.</param>
/// <param name="duration">
/// The duration of the line's visibility, in seconds. If 0 is passed, the line 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 line be obscured by objects closer to the camera.
/// </param>
public static void DrawRay(Ray ray, in Color color, float duration, bool depthTest)
{
Debug.DrawRay(ray.origin, ray.direction, color, duration, depthTest);
}
/// <summary>
/// Draws a ray.
/// </summary>
/// <param name="start">The starting point.</param>
/// <param name="direction">The direction.</param>
public static void DrawRay(Vector3 start, Vector3 direction)
{
DrawRay(start, direction, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a ray.
/// </summary>
/// <param name="start">The starting point.</param>
/// <param name="direction">The direction.</param>
/// <param name="color">The color of the line.</param>
public static void DrawRay(Vector3 start, Vector3 direction, in Color color)
{
DrawRay(start, direction, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a ray.
/// </summary>
/// <param name="start">The starting point.</param>
/// <param name="direction">The direction.</param>
/// <param name="color">The color of the line.</param>
/// <param name="duration">
/// The duration of the line's visibility, in seconds. If 0 is passed, the line is visible for a single frame.
/// </param>
public static void DrawRay(Vector3 start, Vector3 direction, in Color color, float duration)
{
DrawRay(start, direction, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a ray.
/// </summary>
/// <param name="start">The starting point.</param>
/// <param name="direction">The direction.</param>
/// <param name="color">The color of the line.</param>
/// <param name="duration">
/// The duration of the line's visibility, in seconds. If 0 is passed, the line 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 line be obscured by objects closer to the camera.
/// </param>
public static void DrawRay(Vector3 start, Vector3 direction, in Color color, float duration, bool depthTest)
{
Debug.DrawRay(start, direction, color, duration, depthTest);
}
}

View File

@ -0,0 +1,198 @@
using UnityEngine;
using X10D.Drawing;
using X10D.Unity.Numerics;
namespace X10D.Unity;
public static partial class DebugEx
{
/// <summary>
/// Draws a sphere with the specified color.
/// </summary>
/// <param name="center">The center point of the sphere.</param>
/// <param name="radius">The radius of the sphere.</param>
/// <param name="sides">The number of sides to generate.</param>
public static void DrawSphere(Vector3 center, float radius, int sides)
{
DrawSphere(center, radius, sides, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a sphere with the specified color.
/// </summary>
/// <param name="center">The center point of the sphere.</param>
/// <param name="radius">The radius of the sphere.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the sphere.</param>
public static void DrawSphere(Vector3 center, float radius, int sides, in Color color)
{
DrawSphere(center, radius, sides, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a sphere with the specified color and duration.
/// </summary>
/// <param name="center">The center point of the sphere.</param>
/// <param name="radius">The radius of the sphere.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the sphere.</param>
/// <param name="duration">
/// The duration of the sphere's visibility, in seconds. If 0 is passed, the sphere is visible for a single frame.
/// </param>
public static void DrawSphere(Vector3 center, float radius, int sides, in Color color, float duration)
{
DrawSphere(center, radius, sides, Vector2.zero, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a sphere with the specified color and duration.
/// </summary>
/// <param name="center">The center point of the sphere.</param>
/// <param name="radius">The radius of the sphere.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the sphere.</param>
/// <param name="duration">
/// The duration of the sphere's visibility, in seconds. If 0 is passed, the sphere 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 sphere be obscured by objects closer to the camera.
/// </param>
public static void DrawSphere(Vector3 center, float radius, int sides, in Color color, float duration, bool depthTest)
{
DrawSphere(center, radius, sides, Vector2.zero, color, duration, depthTest);
}
/// <summary>
/// Draws a sphere.
/// </summary>
/// <param name="center">The center point of the sphere.</param>
/// <param name="radius">The radius of the sphere.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the sphere.</param>
/// <param name="color">The color of the sphere.</param>
/// <param name="duration">
/// The duration of the sphere's visibility, in seconds. If 0 is passed, the sphere 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 sphere be obscured by objects closer to the camera.
/// </param>
public static void DrawSphere(Vector3 center, float radius, int sides, Vector2 offset, in Color color, float duration,
bool depthTest)
{
DrawSphere(new Sphere(center.ToSystemVector(), radius), sides, offset, color, duration, depthTest);
}
/// <summary>
/// Draws a sphere with the specified color.
/// </summary>
/// <param name="sphere">The sphere to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
public static void DrawSphere(Sphere sphere, int sides)
{
DrawSphere(sphere, sides, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a sphere with the specified color.
/// </summary>
/// <param name="sphere">The sphere to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the sphere.</param>
public static void DrawSphere(Sphere sphere, int sides, Vector2 offset)
{
DrawSphere(sphere, sides, offset, Color.white, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a sphere with the specified color.
/// </summary>
/// <param name="sphere">The sphere to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the sphere.</param>
public static void DrawSphere(Sphere sphere, int sides, in Color color)
{
DrawSphere(sphere, sides, Vector2.zero, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a sphere with the specified color.
/// </summary>
/// <param name="sphere">The sphere to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the sphere.</param>
/// <param name="color">The color of the sphere.</param>
public static void DrawSphere(Sphere sphere, int sides, Vector2 offset, in Color color)
{
DrawSphere(sphere, sides, offset, color, DefaultDrawDuration, DefaultDepthTest);
}
/// <summary>
/// Draws a sphere with the specified color and duration.
/// </summary>
/// <param name="sphere">The sphere to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the sphere.</param>
/// <param name="duration">
/// The duration of the sphere's visibility, in seconds. If 0 is passed, the sphere is visible for a single frame.
/// </param>
public static void DrawSphere(Sphere sphere, int sides, in Color color, float duration)
{
DrawSphere(sphere, sides, Vector2.zero, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a sphere with the specified color and duration.
/// </summary>
/// <param name="sphere">The sphere to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the sphere.</param>
/// <param name="color">The color of the sphere.</param>
/// <param name="duration">
/// The duration of the sphere's visibility, in seconds. If 0 is passed, the sphere is visible for a single frame.
/// </param>
public static void DrawSphere(Sphere sphere, int sides, Vector2 offset, in Color color, float duration)
{
DrawSphere(sphere, sides, offset, color, duration, DefaultDepthTest);
}
/// <summary>
/// Draws a sphere with the specified color and duration.
/// </summary>
/// <param name="sphere">The sphere to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="color">The color of the sphere.</param>
/// <param name="duration">
/// The duration of the sphere's visibility, in seconds. If 0 is passed, the sphere 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 sphere be obscured by objects closer to the camera.
/// </param>
public static void DrawSphere(Sphere sphere, int sides, in Color color, float duration, bool depthTest)
{
DrawSphere(sphere, sides, Vector2.zero, color, duration, depthTest);
}
/// <summary>
/// Draws a sphere.
/// </summary>
/// <param name="sphere">The sphere to draw.</param>
/// <param name="sides">The number of sides to generate.</param>
/// <param name="offset">The drawing offset of the sphere.</param>
/// <param name="color">The color of the sphere.</param>
/// <param name="duration">
/// The duration of the sphere's visibility, in seconds. If 0 is passed, the sphere 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 sphere be obscured by objects closer to the camera.
/// </param>
public static void DrawSphere(Sphere sphere, int sides, in Vector3 offset, in Color color, float duration, bool depthTest)
{
DrawPolyhedron(CreateCircle(sphere.Radius, sides, Vector3.zero), offset, color, duration, depthTest);
DrawPolyhedron(CreateCircle(sphere.Radius, sides, Vector3.left), offset, color, duration, depthTest);
DrawPolyhedron(CreateCircle(sphere.Radius, sides, Vector3.up), offset, color, duration, depthTest);
}
}

417
X10D.Unity/src/DebugEx.cs Normal file
View File

@ -0,0 +1,417 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
using UnityEngine;
using Debug = UnityEngine.Debug;
using Object = UnityEngine.Object;
namespace X10D.Unity;
/// <summary>
/// An extended version of Unity's <see cref="UnityEngine.Debug" /> utility class which offers support for drawing simple
/// primitives.
/// </summary>
public static partial class DebugEx
{
/// <summary>
/// The default value to use for the <c>duration</c> parameter.
/// </summary>
private const float DefaultDrawDuration = 0.0f;
/// <summary>
/// The default value to use for the <c>depthTest</c> parameter.
/// </summary>
private const bool DefaultDepthTest = true;
/// <summary>
/// Gets a value indicating whether this is a debug build.
/// </summary>
/// <value><see langword="true" /> if this is a debug build; otherwise, <see langword="false" />.</value>
// ReSharper disable once InconsistentNaming
public static bool isDebugBuild
{
get => Debug.isDebugBuild;
}
/// <summary>
/// Gets a value indicating whether the developer console is visible.
/// </summary>
/// <value><see langword="true" /> if the developer console is visible; otherwise, <see langword="false" />.</value>
// ReSharper disable once InconsistentNaming
public static bool isDeveloperConsoleVisible
{
get => Debug.developerConsoleVisible;
}
/// <summary>
/// Gets the default Unity debug logger.
/// </summary>
/// <value>The Unity debug logger.</value>
// ReSharper disable once InconsistentNaming
public static ILogger unityLogger
{
get => Debug.unityLogger;
}
/// <summary>
/// Asserts a condition.
/// </summary>
/// <param name="condition">The condition to assert.</param>
[Conditional("UNITY_ASSERTIONS")]
[AssertionMethod]
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void Assert(bool condition)
{
if (condition)
{
return;
}
unityLogger.Log(LogType.Assert, "Assertion failed");
}
/// <summary>
/// Asserts a condition.
/// </summary>
/// <param name="condition">The condition to assert.</param>
/// <param name="context">The object to which the assertion applies.</param>
[Conditional("UNITY_ASSERTIONS")]
[AssertionMethod]
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void Assert(bool condition, Object context)
{
if (condition)
{
return;
}
unityLogger.Log(LogType.Assert, (object)"Assertion failed", context);
}
/// <summary>
/// Asserts a condition.
/// </summary>
/// <param name="condition">The condition to assert.</param>
/// <param name="message">The message to log.</param>
[Conditional("UNITY_ASSERTIONS")]
[AssertionMethod]
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void Assert(bool condition, string? message)
{
if (condition)
{
return;
}
unityLogger.Log(LogType.Assert, message);
}
/// <summary>
/// Asserts a condition.
/// </summary>
/// <param name="condition">The condition to assert.</param>
/// <param name="message">The message to log.</param>
[Conditional("UNITY_ASSERTIONS")]
[AssertionMethod]
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void Assert<T>(bool condition, T? message)
{
if (condition)
{
return;
}
unityLogger.Log(LogType.Assert, message?.ToString());
}
/// <summary>
/// Logs a message to the Unity Console.
/// </summary>
/// <param name="condition">The condition to assert.</param>
/// <param name="message">The message to log.</param>
/// <param name="context">The object to which the assertion applies.</param>
[Conditional("UNITY_ASSERTIONS")]
[AssertionMethod]
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void Assert(bool condition, string? message, Object? context)
{
if (condition)
{
return;
}
unityLogger.Log(LogType.Assert, (object?)message, context);
}
/// <summary>
/// Logs a message to the Unity Console.
/// </summary>
/// <param name="condition">The condition to assert.</param>
/// <param name="message">The message to log.</param>
/// <param name="context">The object to which the assertion applies.</param>
[Conditional("UNITY_ASSERTIONS")]
[AssertionMethod]
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void Assert<T>(bool condition, T? message, Object? context)
{
if (condition)
{
return;
}
unityLogger.Log(LogType.Assert, (object?)message?.ToString(), context);
}
/// <summary>
/// Pauses the editor.
/// </summary>
public static void Break()
{
Debug.Break();
}
/// <summary>
/// Clears the developer console.
/// </summary>
public static void ClearDeveloperConsole()
{
Debug.ClearDeveloperConsole();
}
/// <summary>
/// Populate an unmanaged buffer with the current managed call stack as a sequence of UTF-8 bytes, without allocating GC
/// memory.
/// </summary>
/// <param name="buffer">The target buffer to receive the callstack text.</param>
/// <param name="bufferMax">The maximum number of bytes to write.</param>
/// <param name="projectFolder">The project folder path, to clean up path names.</param>
/// <returns>The number of bytes written into the buffer.</returns>
[MustUseReturnValue("Fewer bytes may be returned than requested.")]
public static unsafe int ExtractStackTraceNoAlloc(byte* buffer, int bufferMax, string projectFolder)
{
return Debug.ExtractStackTraceNoAlloc(buffer, bufferMax, projectFolder);
}
/// <summary>
/// Logs a message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
public static void Log(string? message)
{
Debug.Log(message);
}
/// <summary>
/// Logs a message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
public static void Log<T>(T message)
{
Log(message?.ToString());
}
/// <summary>
/// Logs a message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
/// <param name="context">The object to which the message applies.</param>
public static void Log(string message, Object? context)
{
Debug.Log(message, context);
}
/// <summary>
/// Logs a message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
/// <param name="context">The object to which the message applies.</param>
public static void Log<T>(T message, Object? context)
{
Debug.Log(message?.ToString(), context);
}
/// <summary>
/// Logs an assertion message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
[Conditional("UNITY_ASSERTIONS")]
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void LogAssertion(string? message)
{
unityLogger.Log(LogType.Assert, message);
}
/// <summary>
/// Logs an assertion message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
[Conditional("UNITY_ASSERTIONS")]
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void LogAssertion<T>(T message)
{
unityLogger.Log(LogType.Assert, message?.ToString());
}
/// <summary>
/// Logs an assertion message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
/// <param name="context">The object to which the message applies.</param>
[Conditional("UNITY_ASSERTIONS")]
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void LogAssertion(string message, Object? context)
{
unityLogger.Log(LogType.Assert, (object?)message, context);
}
/// <summary>
/// Logs an assertion message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
/// <param name="context">The object to which the message applies.</param>
[Conditional("UNITY_ASSERTIONS")]
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public static void LogAssertion<T>(T? message, Object? context)
{
unityLogger.Log(LogType.Assert, (object?)message?.ToString(), context);
}
/// <summary>
/// Logs an error message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
public static void LogError(string? message)
{
Debug.LogError(message);
}
/// <summary>
/// Logs an error message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
public static void LogError<T>(T? message)
{
LogError(message?.ToString());
}
/// <summary>
/// Logs an error message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
/// <param name="context">The object to which the message applies.</param>
public static void LogError(string message, Object? context)
{
Debug.LogError(message, context);
}
/// <summary>
/// Logs an error message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
/// <param name="context">The object to which the message applies.</param>
public static void LogError<T>(T? message, Object? context)
{
Debug.LogError(message?.ToString(), context);
}
/// <summary>
/// Logs a formatted error message to the Unity Console.
/// </summary>
/// <param name="format">The format string of the message to log.</param>
/// <param name="args">The format arguments.</param>
public static void LogErrorFormat(string? format, params object?[]? args)
{
Debug.LogErrorFormat(format, args);
}
/// <summary>
/// Logs a formatted error message to the Unity Console.
/// </summary>
/// <param name="context">The object to which this message applies.</param>
/// <param name="format">The format string of the message to log.</param>
/// <param name="args">The format arguments.</param>
public static void LogErrorFormat(Object context, string? format, params object?[]? args)
{
Debug.LogErrorFormat(context, format, args);
}
/// <summary>
/// Logs a formatted message to the Unity Console.
/// </summary>
/// <param name="format">The format string of the message to log.</param>
/// <param name="args">The format arguments.</param>
public static void LogFormat(string? format, params object?[]? args)
{
Debug.LogFormat(format, args);
}
/// <summary>
/// Logs a formatted message to the Unity Console.
/// </summary>
/// <param name="context">The object to which this message applies.</param>
/// <param name="format">The format string of the message to log.</param>
/// <param name="args">The format arguments.</param>
public static void LogFormat(Object context, string? format, params object?[]? args)
{
Debug.LogFormat(context, format, args);
}
/// <summary>
/// Logs a warning message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
public static void LogWarning(string? message)
{
Debug.LogWarning(message);
}
/// <summary>
/// Logs a warning message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
public static void LogWarning<T>(T? message)
{
LogWarning(message?.ToString());
}
/// <summary>
/// Logs a warning message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
/// <param name="context">The object to which the message applies.</param>
public static void LogWarning(string message, Object? context)
{
Debug.LogWarning(message, context);
}
/// <summary>
/// Logs a warning message to the Unity Console.
/// </summary>
/// <param name="message">The message to log.</param>
/// <param name="context">The object to which the message applies.</param>
public static void LogWarning<T>(T? message, Object? context)
{
Debug.LogWarning(message?.ToString(), context);
}
/// <summary>
/// Logs a formatted warning message to the Unity Console.
/// </summary>
/// <param name="format">The format string of the message to log.</param>
/// <param name="args">The format arguments.</param>
public static void LogWarningFormat(string? format, params object?[]? args)
{
Debug.LogWarningFormat(format, args);
}
/// <summary>
/// Logs a formatted warning message to the Unity Console.
/// </summary>
/// <param name="context">The object to which this message applies.</param>
/// <param name="format">The format string of the message to log.</param>
/// <param name="args">The format arguments.</param>
public static void LogWarningFormat(Object context, string? format, params object?[]? args)
{
Debug.LogWarningFormat(context, format, args);
}
}