Gizmos 2D Utilities - BluePixelDev/utilkit GitHub Wiki
Gizmos 2D Utilities
The Gizmos2D
class provides helper methods for drawing 2D shapes in the Unity Editor using Gizmos
. These utilities simplify visual debugging by allowing you to easily draw shapes such as circles, squares, and cones on the XY plane.
DrawWireCircle(Vector3 position, float radius)
Draws a wireframe circle at the given position.
- position: Center of the circle.
- radius: Radius of the circle.
Gizmos2D.DrawWireCircle(transform.position, 2f);
This uses Gizmos.DrawWireSphere
, restricted to the XY plane.
DrawCircle(Vector3 position, float radius)
Draws a circle using line segments.
- position: Center of the circle.
- radius: Radius of the circle.
Gizmos2D.DrawCircle(Vector3.zero, 1.5f);
Constructed with 64
vertices for smoothness.
DrawSquare(Vector3 position, Vector2 size)
Draws a square centered at the specified position.
- position: Center of the square.
- size: Width and height of the square.
Gizmos2D.DrawSquare(transform.position, new Vector2(2f, 2f));
The corners are automatically calculated and connected in order.
DrawCone(Vector3 position, float radius, float angle)
Draws a cone originating from the specified position.
- position: Cone's origin.
- radius: Length of the cone's reach.
- angle: Cone's angle in degrees (clamped to 360).
Gizmos2D.DrawCone(Vector3.zero, 5f, 90f);
This method draws the cone using line segments and includes outer edge lines to visualize the angle spread.