SaintsDraw
allow you to draw arrow, circle, and arc in Unity, using Gizmos or LineRenderer
Unity: 2019.1 or above
-
Using OpenUPM
openupm add today.comes.saintsdraw
-
Using git upm:
add this line to manifest.json in your project
{ "dependencies": { "today.comes.saintsdraw": "https://github.com/TylerTemp/SaintsDraw.git", // your other dependencies... } }
-
Using a unitypackage:
Go to the Release Page to download a desired version of unitypackage and import it to your project
-
Using a git submodule:
git submodule add https://github.com/TylerTemp/SaintsDraw.git Assets/SaintsDraw
Using Arrow.Draw
to draw an arrow, which has parameters:
Vector3 from
point where the arrow starts (tail)Vector3 to
points where the arrow ends (head)float arrowHeadLength = 0.5f
float arrowHeadAngle = 20.0f
Vector3? up = null
up direction of the arrow, default isVector3.up
. This is useful when you have some rotation on the arrow. The arrow is always perpendicular to thisup
direction.
Append a LineRenderer
as the first parameter to draw the arrow using LineRenderer
using SaintsDraw;
Arrow.Draw(Vector3.zero, Vector3.one);
Using Circle.Draw
to draw an circle (disk), which has parameters:
Vector3 center
center of the circlefloat radius
radius of the circleVector3 upward
up direction of the circle. The circle is always perpendicular to this value. UsuallyVector3.up
is usedint numSegments
how many segments to draw for the arc. The bigger it is, the smoother the arc is
Using Circle.DrawBySegCount
to draw an circle with fixed segment steps, which means each segment will have the same angle. It has the same parameters as Circle.Draw
except int numSegments
is replaced by float segAngle
.
Append a LineRenderer
as the first parameter to draw the arc using LineRenderer
using SaintsDraw;
Circle.Draw(Vector3.zero, 5f, Vector3.up, 40);
Using Arc.Draw
to draw an arc, which has parameters:
-
Vector3 center
center of the arc -
float radius
radius of the arc -
float fromArc
angle to start -
float toArc
angle to end -
Vector3 upward
up direction of the arc. The arc is always perpendicular to this value. UsuallyVector3.up
is used -
Vector3 plate
as the arc no has a plate which is perpendicular to the arc, this parameter is used to determine the plate's start point. It'll be automatically put on the plate defined by theupward
direction.Usually
Vector3.left
orVector3.forward
is used -
int numSegments
how many segments to draw for the arc. The bigger it is, the smoother the arc is
Using Arc.DrawBySegCount
to draw an with fixed segment steps, which means each segment will have the same angle. It has the same parameters as Arc.Draw
except int numSegments
is replaced by float segAngle
.
Append a LineRenderer
as the first parameter to draw the arc using LineRenderer
using SaintsDraw;
Arc.Draw(Vector3.zero, 5f, 60f, 120f, Vector3.up, Vector3.left, 40);
UIGizmos.DrawWireRectTransform(RectTransform rectTransform)
Draw a wireframe of a RectTransform in the scene view. This works even the RectTransform
has rotation and scale.
UIGizmos.DrawWireRectTransform(GetComponent<RectTransform>());
using (new ColorScoop(Color.green))
{
Arrow.Draw(Vector2.zero, Vector2.up);
}
Useful if you want to draw gizmos in local space inheriting parent's scale and rotation
using (new MatrixScoop(transform.localToWorldMatrix))
{
Arrow.Draw(Vector2.zero, Vector2.up);
}
this will normalized your angle, which allow over 360 but will has no overlap
(float normFromArc, float normToArc) = Arc.NormalAngleRange(_fromArc, _toArc);
this will display an arrow from arc center to the angle you want to check, helpful when testing upward
and plate
Vector3 startPos = Arc.GetDirection(_upward, _plate, angle).normalized * _arcRadis;
Arrow.Draw(Vector3.zero, startPos);