void OnSceneGUI() { BezierUtils.DrawSplineDetailed(spline); for (int i = 0; i < spline.Count; i++) { BezierUtils.DrawBezierPoint(spline[i], i + 1, false); } }
void OnSceneGUI() { if (spline != null && !spline.Equals(null)) { Event e = Event.current; if (e.type == EventType.ValidateCommand) { if (e.commandName == "Delete") { RemovePointAt(spline.IndexOf(point)); e.type = EventType.Ignore; return; } else if (e.commandName == "Duplicate") { DuplicatePointAt(spline.IndexOf(point)); e.type = EventType.Ignore; } } if (e.isKey && e.type == EventType.KeyDown && e.keyCode == KeyCode.Delete) { RemovePointAt(spline.IndexOf(point)); e.Use(); return; } BezierUtils.DrawSplineDetailed(spline); for (int i = 0; i < spline.Count; i++) { BezierUtils.DrawBezierPoint(spline[i], i + 1, spline[i] == point); } } else { BezierUtils.DrawBezierPoint(point, 0, true); } // Draw translate handles for control points if (Event.current.alt) { return; } if (Tools.current != Tool.Move) { controlPointRotationsInitialized = false; return; } if (!controlPointRotationsInitialized) { precedingPointRotation = Quaternion.LookRotation(point.precedingControlPointPosition - point.position); followingPointRotation = Quaternion.LookRotation(point.followingControlPointPosition - point.position); controlPointRotationsInitialized = true; } EditorGUI.BeginChangeCheck(); Vector3 position = Handles.PositionHandle(point.precedingControlPointPosition, Tools.pivotRotation == PivotRotation.Local ? precedingPointRotation : Quaternion.identity); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(point, "Move Control Point"); point.precedingControlPointPosition = position; } EditorGUI.BeginChangeCheck(); position = Handles.PositionHandle(point.followingControlPointPosition, Tools.pivotRotation == PivotRotation.Local ? followingPointRotation : Quaternion.identity); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(point, "Move Control Point"); point.followingControlPointPosition = position; } }
public override void OnInspectorGUI() { Color c = GUI.color; if (spline != null && !spline.Equals(null)) { BezierUtils.DrawSplineInspectorGUI(spline); if (point == null || point.Equals(null)) { return; } EditorGUILayout.Space(); DrawSeparator(); GUILayout.BeginHorizontal(); if (GUILayout.Button("<-", GUILayout.Width(45))) { int prevIndex = spline.IndexOf(point) - 1; if (prevIndex < 0) { prevIndex = spline.Count - 1; } Selection.activeTransform = spline[prevIndex].transform; return; } GUILayout.Box("Selected Point: " + (spline.IndexOf(point) + 1) + " / " + spline.Count, GUILayout.ExpandWidth(true)); if (GUILayout.Button("->", GUILayout.Width(45))) { int nextIndex = spline.IndexOf(point) + 1; if (nextIndex >= spline.Count) { nextIndex = 0; } Selection.activeTransform = spline[nextIndex].transform; return; } GUILayout.EndHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button("Decrement Point's Index")) { int index = spline.IndexOf(point); int newIndex = index - 1; if (newIndex < 0) { newIndex = spline.Count - 1; } if (index != newIndex) { Undo.IncrementCurrentGroup(); Undo.RegisterCompleteObjectUndo(point.transform.parent, "Change point index"); spline.SwapPointsAt(index, newIndex); SceneView.RepaintAll(); } } if (GUILayout.Button("Increment Point's Index")) { int index = spline.IndexOf(point); int newIndex = index + 1; if (newIndex >= spline.Count) { newIndex = 0; } if (index != newIndex) { Undo.IncrementCurrentGroup(); Undo.RegisterCompleteObjectUndo(point.transform.parent, "Change point index"); spline.SwapPointsAt(index, newIndex); SceneView.RepaintAll(); } } EditorGUILayout.Space(); if (GUILayout.Button("Insert Point Before")) { InsertNewPointAt(spline.IndexOf(point)); } if (GUILayout.Button("Insert Point After")) { InsertNewPointAt(spline.IndexOf(point) + 1); } EditorGUILayout.Space(); if (GUILayout.Button("Duplicate Point")) { DuplicatePointAt(spline.IndexOf(point)); } EditorGUILayout.Space(); } EditorGUI.BeginChangeCheck(); BezierPoint.HandleMode handleMode = (BezierPoint.HandleMode)EditorGUILayout.EnumPopup("Handle Mode", point.handleMode); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(point, "Change Point Handle Mode"); point.handleMode = handleMode; SceneView.RepaintAll(); } EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); Vector3 position = EditorGUILayout.Vector3Field("Preceding Control Point Local Position", point.precedingControlPointLocalPosition); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(point, "Change Point Position"); point.precedingControlPointLocalPosition = position; SceneView.RepaintAll(); } EditorGUI.BeginChangeCheck(); position = EditorGUILayout.Vector3Field("Following Control Point Local Position", point.followingControlPointLocalPosition); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(point, "Change Point Position"); point.followingControlPointLocalPosition = position; SceneView.RepaintAll(); } EditorGUILayout.Space(); if (GUILayout.Button("Swap Control Points")) { Undo.RecordObject(point, "Swap Control Points"); Vector3 precedingControlPointLocalPos = point.precedingControlPointLocalPosition; point.precedingControlPointLocalPosition = point.followingControlPointLocalPosition; point.followingControlPointLocalPosition = precedingControlPointLocalPos; SceneView.RepaintAll(); } EditorGUILayout.Space(); DrawSeparator(); if (spline != null && !spline.Equals(null)) { GUI.color = RESET_POINT_BUTTON_COLOR; if (GUILayout.Button("Reset Point")) { ResetEndPointAt(spline.IndexOf(point)); SceneView.RepaintAll(); } EditorGUILayout.Space(); GUI.color = REMOVE_POINT_BUTTON_COLOR; if (spline.Count <= 2) { GUI.enabled = false; } if (GUILayout.Button("Remove Point")) { RemovePointAt(spline.IndexOf(point)); } GUI.enabled = true; } GUI.color = c; }
public override void OnInspectorGUI() { BezierUtils.DrawSplineInspectorGUI(spline); }