SaintsDraw
A Unity plugin for gizmos and LineRenderer drawing in inspector
today.comes.saintsdraw Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/saintsdraw.git README Markdown
Copy this to your project's README.md
## Installation
Add **SaintsDraw** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/saintsdraw.git
```
[](https://www.pkglnk.dev/pkg/saintsdraw)README
SaintsDraw
SaintsDraw allow you to draw arrow, circle, and arc in Unity, using Gizmos or LineRenderer
Unity: 2019.1 or above
Installation
Using OpenUPM
openupm add today.comes.saintsdrawUsing 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
Change Log
1.0.4
Make the arrow drawing helper public
See the full change log.
Draw
Arrow
Using Arrow.Draw to draw an arrow, which has parameters:
Vector3 frompoint where the arrow starts (tail)Vector3 topoints where the arrow ends (head)float arrowHeadLength = 0.5ffloat arrowHeadAngle = 20.0fVector3? up = nullup direction of the arrow, default isVector3.up. This is useful when you have some rotation on the arrow. The arrow is always perpendicular to thisupdirection.
Append a LineRenderer as the first parameter to draw the arrow using LineRenderer
using SaintsDraw;
Arrow.Draw(Vector3.zero, Vector3.one);
Circle (Disk)
Using Circle.Draw to draw an circle (disk), which has parameters:
Vector3 centercenter of the circlefloat radiusradius of the circleVector3 upwardup direction of the circle. The circle is always perpendicular to this value. UsuallyVector3.upis usedint numSegmentshow 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);
Arc
Using Arc.Draw to draw an arc, which has parameters:
Vector3 centercenter of the arcfloat radiusradius of the arcfloat fromArcangle to startfloat toArcangle to endVector3 upwardup direction of the arc. The arc is always perpendicular to this value. UsuallyVector3.upis usedVector3 plateas 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 theupwarddirection.Usually
Vector3.leftorVector3.forwardis usedint numSegmentshow 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);
DrawWireRectTransform
UIGizmos.DrawWireRectTransform(RectTransform rectTransform, Camera camera=null, float distance=5f)
Draw a wireframe of a RectTransform in the scene view. This works even the RectTransform has rotation and scale.
Parameters:
RectTransform rectTransformthe RectTransform to drawCamera camerathe camera of the canvas.nullforOverlaytype.float distancethe distance from the camera to the wireframe. This only works if you pass the camera parameter which is the target camera of the canvas, and ensure yourrectTransformis under this canvas too.
UIGizmos.DrawWireRectTransform(GetComponent<RectTransform>());
Some Tools
Gizmos Color
using (new ColorScoop(Color.green))
{
Arrow.Draw(Vector2.zero, Vector2.up);
}
Gizmos Matrix
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);
}
Arc Tools
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);
Comments
No comments yet. Be the first!
Sign in to join the conversation
Sign In