private void OnSceneGUI() { BezierSpline spline = (BezierSpline)target; BezierUtils.DrawSplineDetailed(spline); for (int i = 0; i < spline.Count; i++) { BezierUtils.DrawBezierPoint(spline[i], i + 1, false); } if (BezierSettings.ShowEvenlySpacedPoints) { BezierUtils.DrawSplineEvenlySpacedPoints(spline); } if (BezierUtils.QuickEditSplineMode) { // Execute quick edit mode's scene GUI only once (otherwise things can get ugly when multiple splines are selected) if (spline == allSplines[0]) { BezierUtils.QuickEditModeSceneGUI(allSplines); HandleUtility.AddDefaultControl(0); } return; } }
private void OnSceneGUI() { BezierSpline spline = (BezierSpline)target; BezierUtils.DrawSplineDetailed(spline); for (int i = 0; i < spline.Count; i++) { BezierUtils.DrawBezierPoint(spline[i], i + 1, false); } }
private void OnSceneGUI() { BezierPoint point = (BezierPoint)target; if (!point) { return; } if (CheckCommands()) { return; } // OnSceneGUI is called separately for each selected point, // make sure that the spline is drawn only once, not multiple times if (point == allPoints[0]) { for (int i = 0; i < selection.Length; i++) { BezierSpline spline = selection[i].spline; if (spline) { BezierPoint[] points = selection[i].points; BezierUtils.DrawSplineDetailed(spline); for (int j = 0, k = 0; j < spline.Count; j++) { bool isSelected = spline[j] == points[k]; if (isSelected && k < points.Length - 1) { k++; } if (!isSelected) { BezierUtils.DrawBezierPoint(spline[j], j + 1, false); } } } } if (allPoints.Length > 1) { Handles.BeginGUI(); GUIStyle style = "PreOverlayLabel"; // Taken from: https://github.com/Unity-Technologies/UnityCsReference/blob/f78f4093c8a2b45949a847cdc704cf209dcf2f36/Editor/Mono/EditorGUI.cs#L629 EditorGUI.DropShadowLabel(new Rect(new Vector2(0f, 0f), style.CalcSize(MULTI_EDIT_TIP)), MULTI_EDIT_TIP, style); Handles.EndGUI(); } } // When Control key is pressed, BezierPoint gizmos should be drawn on top of Transform handles in order to allow selecting/deselecting points // If Alt key is pressed, Transform handles aren't drawn at all, so BezierPoint gizmos can be drawn immediately Event e = Event.current; if (e.alt || !e.control) { BezierUtils.DrawBezierPoint(point, point.Internal_Index + 1, true); } // Camera rotates with Alt key, don't interfere if (e.alt) { return; } int pointIndex = -1; for (int i = 0; i < allPoints.Length; i++) { if (allPoints[i] == point) { pointIndex = i; break; } } Tool tool = Tools.current; if (previousTool != tool) { controlPointRotationsInitialized = false; previousTool = tool; } // Draw Transform handles for control points switch (Tools.current) { case Tool.Move: if (!controlPointRotationsInitialized) { for (int i = 0; i < allPoints.Length; i++) { BezierPoint p = allPoints[i]; precedingPointRotations[i] = Quaternion.LookRotation(p.precedingControlPointPosition - p.position); followingPointRotations[i] = Quaternion.LookRotation(p.followingControlPointPosition - p.position); } controlPointRotationsInitialized = true; } // No need to show gizmos for control points in Autoconstruct mode Vector3 position; if (!point.Internal_Spline || point.Internal_Spline.Internal_AutoConstructMode == SplineAutoConstructMode.None) { EditorGUI.BeginChangeCheck(); position = Handles.PositionHandle(point.precedingControlPointPosition, Tools.pivotRotation == PivotRotation.Local ? precedingPointRotations[pointIndex] : 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 ? followingPointRotations[pointIndex] : Quaternion.identity); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(point, "Move Control Point"); point.followingControlPointPosition = position; } } EditorGUI.BeginChangeCheck(); position = Handles.PositionHandle(point.position, Tools.pivotRotation == PivotRotation.Local ? point.rotation : Quaternion.identity); if (EditorGUI.EndChangeCheck()) { if (!e.shift) { Undo.RecordObject(point, "Move Point"); Undo.RecordObject(point.transform, "Move Point"); point.position = position; } else { Vector3 delta = position - point.position; for (int i = 0; i < allPoints.Length; i++) { Undo.RecordObject(allPoints[i], "Move Point"); Undo.RecordObject(allPoints[i].transform, "Move Point"); allPoints[i].position += delta; } } } break; case Tool.Rotate: Quaternion handleRotation; if (Tools.pivotRotation == PivotRotation.Local) { handleRotation = point.rotation; controlPointRotationsInitialized = false; } else { if (!controlPointRotationsInitialized) { for (int i = 0; i < allPoints.Length; i++) { precedingPointRotations[i] = Quaternion.identity; } controlPointRotationsInitialized = true; } handleRotation = precedingPointRotations[pointIndex]; } EditorGUI.BeginChangeCheck(); Quaternion rotation = Handles.RotationHandle(handleRotation, point.position); if (EditorGUI.EndChangeCheck()) { float angle; Vector3 axis; (Quaternion.Inverse(handleRotation) * rotation).ToAngleAxis(out angle, out axis); axis = handleRotation * axis; if (!e.shift) { Undo.RecordObject(point.transform, "Rotate Point"); Vector3 localAxis = point.transform.InverseTransformDirection(axis); point.localRotation *= Quaternion.AngleAxis(angle, localAxis); } else { for (int i = 0; i < allPoints.Length; i++) { Undo.RecordObject(allPoints[i].transform, "Rotate Point"); Vector3 localAxis = allPoints[i].transform.InverseTransformDirection(axis); allPoints[i].localRotation *= Quaternion.AngleAxis(angle, localAxis); } } if (Tools.pivotRotation == PivotRotation.Global) { precedingPointRotations[pointIndex] = rotation; } } break; case Tool.Scale: EditorGUI.BeginChangeCheck(); Vector3 scale = Handles.ScaleHandle(point.localScale, point.position, point.rotation, HandleUtility.GetHandleSize(point.position)); if (EditorGUI.EndChangeCheck()) { if (!e.shift) { Undo.RecordObject(point.transform, "Scale Point"); point.localScale = scale; } else { Vector3 delta = new Vector3(1f, 1f, 1f); Vector3 prevScale = point.localScale; if (prevScale.x != 0f) { delta.x = scale.x / prevScale.x; } if (prevScale.y != 0f) { delta.y = scale.y / prevScale.y; } if (prevScale.z != 0f) { delta.z = scale.z / prevScale.z; } for (int i = 0; i < allPoints.Length; i++) { Undo.RecordObject(allPoints[i].transform, "Scale Point"); prevScale = allPoints[i].localScale; prevScale.Scale(delta); allPoints[i].localScale = prevScale; } } } break; } if (e.control) { BezierUtils.DrawBezierPoint(point, point.Internal_Index + 1, true); } }