private static void AddWaypointToGroupOnClick(WaypointGroup group, int afterIndex, Vector3 worldPosition)
{
if (Event.current.alt)
{
// when using alt the user is likely panning around an object, ignore the add method.
return;
}
Handles.Label(worldPosition, "Inserted waypoint at: " + worldPosition);
Handles.color = Color.green;
Handles.SphereCap(-1, worldPosition, Quaternion.identity, 0.5f);
var afterIndexClamped = Mathf.Max(0, afterIndex - 1);
if (afterIndexClamped > 0 && afterIndexClamped < group.waypoints.Length)
{
Handles.DrawAAPolyLine(LineWidth, group.waypoints[afterIndexClamped].transform.position, worldPosition);
}
Handles.color = Color.white;
// Connect from the last to a new waypoint
if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
{
Undo.RecordObject(group, "Added waypoint");
group.InsertWaypointAfter(group.transform.worldToLocalMatrix * (worldPosition - group.transform.localPosition), afterIndex);
_selectedWaypointGroup = group;
_selectedWaypointIndex = afterIndex;
EditorUtility.SetDirty(group);
}
}