Skip to content

Commit

Permalink
Implementation of pull request SebLague#93 by krisrok
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JerryVerhoeven committed Sep 18, 2023
1 parent d9c335a commit cb5a992
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions Assets/PathCreator/Core/Editor/PathEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public class PathEditor : Editor

Color handlesStartCol;

private Quaternion handleRotation = Quaternion.identity;
private bool isSceneViewMouseDown;

// Constants
const int bezierPathTab = 0;
const int vertexPathTab = 1;
Expand Down Expand Up @@ -134,7 +137,9 @@ void DrawBezierPathInspector()

// If a point has been selected
if (handleIndexToDisplayAsTransform != -1)
{
{
UpdateHandleRotation(handleIndexToDisplayAsTransform);

EditorGUILayout.LabelField("Selected Point:");

using (new EditorGUI.IndentLevelScope())
Expand Down Expand Up @@ -649,14 +654,12 @@ void DrawHandle(int i)
bezierPath.SetAnchorNormalAngle(i / 3, anchorAngleHandle.angle - handleRotOffset);
}
}

}
}
else
{
handlePosition = Handles.DoPositionHandle(handlePosition, Quaternion.identity);
handlePosition = Handles.DoPositionHandle(handlePosition, handleRotation);
}

}
}

switch (handleInputType)
{
Expand Down Expand Up @@ -704,11 +707,32 @@ void DrawHandle(int i)
{
Undo.RecordObject(creator, "Move point");
bezierPath.MovePoint(i, localHandlePosition);

}

}

}
}

private void UpdateHandleRotation(int i)
{
var rot = Quaternion.identity;
if (Tools.pivotRotation == PivotRotation.Local)
{
var i3 = i % 3;

var t = creator.path.GetClosestTimeOnPath(bezierPath.GetPoint(i));
rot = creator.path.GetRotation(t, bezierPath.IsClosed ? EndOfPathInstruction.Loop : EndOfPathInstruction.Stop);
if (i3 != 0)
{
var anchorIndex = 0;
if (i3 == 1)
anchorIndex = i - 1;
else if (i3 == 2)
anchorIndex = i + 1;

rot = Quaternion.LookRotation(bezierPath.GetPoint(i) - bezierPath.GetPoint(anchorIndex), rot * Vector3.up);
}
}
handleRotation = rot;
}

#endregion

#region Internal methods
Expand Down

0 comments on commit cb5a992

Please sign in to comment.