Skip to content

Introduce local editing mode for path points #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions Path Creator Project/Assets/PathCreator/Core/Editor/PathEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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 @@ -278,7 +281,17 @@ void OnSceneGUI () {

EventType eventType = Event.current.type;

using (var check = new EditorGUI.ChangeCheckScope ()) {
if (eventType == EventType.MouseDown)
{
isSceneViewMouseDown = true;
}
else if (eventType == EventType.MouseUp)
{
isSceneViewMouseDown = false;
}

using (var check = new EditorGUI.ChangeCheckScope())
{
handlesStartCol = Handles.color;
switch (data.tabIndex) {
case bezierPathTab:
Expand Down Expand Up @@ -553,8 +566,15 @@ void DrawHandle (int i) {
}
}

} else {
handlePosition = Handles.DoPositionHandle (handlePosition, Quaternion.identity);
}
else
{
HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));

if(isSceneViewMouseDown == false)
UpdateHandleRotation(i);

handlePosition = Handles.DoPositionHandle(handlePosition, handleRotation);
}

}
Expand All @@ -579,6 +599,7 @@ void DrawHandle (int i) {
handleIndexToDisplayAsTransform = -1; // disable move tool if clicking on point under move tool
} else {
handleIndexToDisplayAsTransform = i;
UpdateHandleRotation(i);
}
}
Repaint ();
Expand All @@ -601,6 +622,29 @@ void DrawHandle (int i) {

}

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