Skip to content

Instantly share code, notes, and snippets.

@kraj0t
Last active February 14, 2022 02:26
Show Gist options
  • Save kraj0t/da929fd9811bc47a5ab95009e07656ea to your computer and use it in GitHub Desktop.
Save kraj0t/da929fd9811bc47a5ab95009e07656ea to your computer and use it in GitHub Desktop.
Editor GUI; draw dotted lines using Handles
// Somewhere in your OnSceneGUI() ...
// Draw dotted lines.
var handlesColorBkp = Handles.color;
Handles.color = new Color(0f, 0f, 0.5f);
for (int i = 0; i < points.Length - 1; i++)
{
Handles.DrawDottedLine(points[i], points[i + 1], DOTTED_LINE_SIZE);
}
Handles.color = handlesColorBkp;
// Draw drag gizmos.
for (int i = 0; i < points.Length; ++i)
{
using (var check = new EditorGUI.ChangeCheckScope())
{
var handleSize = line.Thickness * POSITION_HANDLE_SIZE_MULTIPLIER;
var handleSnap = Vector3.one * 0.5f;
var pos = Handles.FreeMoveHandle(points[i], Quaternion.identity, handleSize, handleSnap,
Handles.SphereHandleCap);
pos.z = 0;
// Record undo state.
if (check.changed)
{
Undo.RecordObject(line, "Dragged Line Point");
line.Points[i] = pos;
var graphic = line.GetComponent<Graphic>();
graphic.SetVerticesDirty();
Repaint();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment