void Hotkeys() { Event e = Event.current; switch (e.type) { case EventType.ValidateCommand: if (e.commandName == "UndoRedoPerformed") { if (onUpdateSpline != null) { onUpdateSpline(spline); } } break; case EventType.KeyDown: if (e.keyCode == KeyCode.I) { if ((e.modifiers & (EventModifiers.Control | EventModifiers.Command)) != 0) { spline.Flip(); } } break; } }
override public void OnInspectorGUI() { Bezier3DSpline spline = target as Bezier3DSpline; ValidateSelected(); EditorGUILayout.LabelField("Spline settings"); EditorGUI.indentLevel = 1; EditorGUI.BeginChangeCheck(); int steps = spline.cacheDensity; steps = EditorGUILayout.DelayedIntField("Cache density", steps); if (EditorGUI.EndChangeCheck()) { spline.SetCacheDensity(steps); if (onUpdateSpline != null) { onUpdateSpline(spline); } } EditorGUI.BeginChangeCheck(); bool closed = spline.closed; closed = EditorGUILayout.Toggle(new GUIContent("Closed", "Generate an extra curve, connecting the final point to the first point."), closed); if (EditorGUI.EndChangeCheck()) { spline.SetClosed(closed); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } Rect position = EditorGUILayout.GetControlRect(false, 19f, EditorStyles.numberField); position.xMin += EditorGUIUtility.labelWidth; Rect flipRect = new Rect(position.x, position.y, position.width, position.height); if (GUI.Button(flipRect, new GUIContent("Flip", "Flip spline direction."))) { spline.Flip(); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } EditorGUI.indentLevel = 0; EditorGUILayout.Space(); if (activeKnot != -1) { EditorGUILayout.LabelField("Selected point"); EditorGUI.indentLevel = 1; Bezier3DSpline.Knot knot = spline.GetKnot(activeKnot); position = EditorGUILayout.GetControlRect(false, 19f, EditorStyles.numberField); position.xMin += EditorGUIUtility.labelWidth; EditorGUI.BeginChangeCheck(); bool orientation = knot.orientation != null; Rect orientationRect = new Rect(position.x, position.y, position.height, position.height); orientation = GUI.Toggle(orientationRect, orientation, new GUIContent("O", "Orientation Anchor"), "Button"); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Toggle Bezier Orientation Anchor"); if (orientation) { knot.orientation = Quaternion.identity; } else { knot.orientation = null; } spline.SetKnot(activeKnot, knot); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } EditorGUI.BeginChangeCheck(); bool auto = knot.auto != 0f; Rect autoRect = new Rect(position.x + position.height + 4, position.y, position.height, position.height); auto = GUI.Toggle(autoRect, auto, new GUIContent("A", "Auto Handles"), "Button"); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Toggle Bezier Auto Handles"); if (auto) { knot.auto = 0.33f; } else { knot.auto = 0f; } spline.SetKnot(activeKnot, knot); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } if (orientation) { EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); Vector3 orientationEuler = knot.orientation.Value.eulerAngles; orientationEuler = EditorGUILayout.Vector3Field("Orientation", orientationEuler); if (EditorGUI.EndChangeCheck()) { knot.orientation = Quaternion.Euler(orientationEuler); spline.SetKnot(activeKnot, knot); SceneView.RepaintAll(); } } if (auto) { EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); knot.position = EditorGUILayout.Vector3Field("Position", knot.position); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Edit Bezier Point"); spline.SetKnot(activeKnot, knot); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } EditorGUI.BeginChangeCheck(); knot.auto = EditorGUILayout.FloatField("Distance", knot.auto); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Edit Bezier Point"); spline.SetKnot(activeKnot, knot); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } } else { EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); knot.position = EditorGUILayout.Vector3Field("Position", knot.position); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Edit Bezier Point"); spline.SetKnot(activeKnot, knot); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } EditorGUI.BeginChangeCheck(); knot.handleIn = EditorGUILayout.Vector3Field("Handle in", knot.handleIn); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Edit Bezier Handle"); if (mirror) { knot.handleOut = -knot.handleIn; } spline.SetKnot(activeKnot, knot); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } EditorGUI.BeginChangeCheck(); knot.handleOut = EditorGUILayout.Vector3Field("Handle out", knot.handleOut); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Edit Bezier Handle"); if (mirror) { knot.handleIn = -knot.handleOut; } spline.SetKnot(activeKnot, knot); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } } } }