Skip to content

Commit cb5a992

Browse files
Implementation of pull request SebLague#93 by krisrok
Introduce local editing mode for path points SebLague#93. Not sure If I did this exactly right because most of the code locations don't seem to match but it sortof works.
1 parent d9c335a commit cb5a992

1 file changed

Lines changed: 35 additions & 11 deletions

File tree

Assets/PathCreator/Core/Editor/PathEditor.cs

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public class PathEditor : Editor
6161

6262
Color handlesStartCol;
6363

64+
private Quaternion handleRotation = Quaternion.identity;
65+
private bool isSceneViewMouseDown;
66+
6467
// Constants
6568
const int bezierPathTab = 0;
6669
const int vertexPathTab = 1;
@@ -134,7 +137,9 @@ void DrawBezierPathInspector()
134137

135138
// If a point has been selected
136139
if (handleIndexToDisplayAsTransform != -1)
137-
{
140+
{
141+
UpdateHandleRotation(handleIndexToDisplayAsTransform);
142+
138143
EditorGUILayout.LabelField("Selected Point:");
139144

140145
using (new EditorGUI.IndentLevelScope())
@@ -649,14 +654,12 @@ void DrawHandle(int i)
649654
bezierPath.SetAnchorNormalAngle(i / 3, anchorAngleHandle.angle - handleRotOffset);
650655
}
651656
}
652-
653-
}
657+
}
654658
else
655659
{
656-
handlePosition = Handles.DoPositionHandle(handlePosition, Quaternion.identity);
660+
handlePosition = Handles.DoPositionHandle(handlePosition, handleRotation);
657661
}
658-
659-
}
662+
}
660663

661664
switch (handleInputType)
662665
{
@@ -704,11 +707,32 @@ void DrawHandle(int i)
704707
{
705708
Undo.RecordObject(creator, "Move point");
706709
bezierPath.MovePoint(i, localHandlePosition);
707-
708-
}
709-
710-
}
711-
710+
}
711+
}
712+
713+
private void UpdateHandleRotation(int i)
714+
{
715+
var rot = Quaternion.identity;
716+
if (Tools.pivotRotation == PivotRotation.Local)
717+
{
718+
var i3 = i % 3;
719+
720+
var t = creator.path.GetClosestTimeOnPath(bezierPath.GetPoint(i));
721+
rot = creator.path.GetRotation(t, bezierPath.IsClosed ? EndOfPathInstruction.Loop : EndOfPathInstruction.Stop);
722+
if (i3 != 0)
723+
{
724+
var anchorIndex = 0;
725+
if (i3 == 1)
726+
anchorIndex = i - 1;
727+
else if (i3 == 2)
728+
anchorIndex = i + 1;
729+
730+
rot = Quaternion.LookRotation(bezierPath.GetPoint(i) - bezierPath.GetPoint(anchorIndex), rot * Vector3.up);
731+
}
732+
}
733+
handleRotation = rot;
734+
}
735+
712736
#endregion
713737

714738
#region Internal methods

0 commit comments

Comments
 (0)