protected override void OnSceneGUI() { base.OnSceneGUI(); serializedObject.Update(); var rotation = endPoint.FindPropertyRelative("rotation"); if (Tools.current == Tool.Move) { EditorGUI.BeginChangeCheck(); Vector3 newTargetPosition = Handles.PositionHandle(LineData.GetPoint(1), Quaternion.identity); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(LineData, "Change Simple Point Position"); LineData.SetPoint(1, newTargetPosition); } } else if (Tools.current == Tool.Rotate) { EditorGUI.BeginChangeCheck(); Quaternion newTargetRotation = Handles.RotationHandle(rotation.quaternionValue, LineData.GetPoint(1)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(LineData, "Change Simple Point Rotation"); rotation.quaternionValue = newTargetRotation; } } serializedObject.ApplyModifiedProperties(); }
protected override void OnSceneGUI() { base.OnSceneGUI(); // We skip the first point as it should always remain at the GameObject's local origin (Pose.ZeroIdentity) for (int i = 0; i < 4; i++) { bool isTangentHandle = i % 3 != 0; serializedObject.Update(); bool isLastPoint = i == 3; var controlPointPosition = LineData.GetPoint(i); var controlPointProperty = controlPoints.FindPropertyRelative("point" + (i + 1)); // Draw our tangent lines Handles.color = Color.gray; if (i == 0) { Handles.DrawLine(LineData.GetPoint(0), LineData.GetPoint(1)); } else if (!isTangentHandle) { Handles.DrawLine(LineData.GetPoint(i), LineData.GetPoint(i - 1)); if (!isLastPoint) { Handles.DrawLine(LineData.GetPoint(i), LineData.GetPoint(i + 1)); } } Handles.color = isTangentHandle ? Color.white : Color.green; float handleSize = HandleUtility.GetHandleSize(controlPointPosition); if (Handles.Button(controlPointPosition, Quaternion.identity, handleSize * HandleSizeModifier, handleSize * PickSizeModifier, Handles.DotHandleCap)) { selectedHandleIndex = i; } // Draw our handles if (Tools.current == Tool.Move && selectedHandleIndex == i) { EditorGUI.BeginChangeCheck(); var newTargetPosition = Handles.PositionHandle(controlPointPosition, Quaternion.identity); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(LineData, "Change Bezier Point Position"); LineData.SetPoint(i, newTargetPosition); } } serializedObject.ApplyModifiedProperties(); } }
protected override void OnSceneGUI() { base.OnSceneGUI(); // We skip the first point as it should always remain at the GameObject's local origin (Pose.ZeroIdentity) for (int i = 1; i < controlPoints?.arraySize; i++) { bool isTangentHandle = i % 3 != 0; serializedObject.Update(); bool isLastPoint = i == controlPoints.arraySize - 1; var controlPointPosition = LineData.GetPoint(i); var controlPointProperty = controlPoints.GetArrayElementAtIndex(i); var controlPointRotation = controlPointProperty.FindPropertyRelative("rotation"); // Draw our tangent lines Handles.color = Color.gray; if (i == 1) { Handles.DrawLine(LineData.GetPoint(0), LineData.GetPoint(1)); } else if (!isTangentHandle) { Handles.DrawLine(LineData.GetPoint(i), LineData.GetPoint(i - 1)); if (!isLastPoint) { Handles.DrawLine(LineData.GetPoint(i), LineData.GetPoint(i + 1)); } } Handles.color = isTangentHandle ? Color.white : Color.green; float handleSize = HandleUtility.GetHandleSize(controlPointPosition); if (Handles.Button(controlPointPosition, controlPointRotation.quaternionValue, handleSize * HandleSizeModifier, handleSize * PickSizeModifier, Handles.DotHandleCap)) { selectedHandleIndex = i; } // Draw our handles if (Tools.current == Tool.Move && selectedHandleIndex == i) { EditorGUI.BeginChangeCheck(); var newTargetPosition = Handles.PositionHandle(controlPointPosition, controlPointRotation.quaternionValue); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(LineData, "Change Spline Point Position"); LineData.SetPoint(i, newTargetPosition); } if (isLastPoint) { DrawSceneControlOptionButtons(controlPointPosition); } } else if (Tools.current == Tool.Rotate && selectedHandleIndex == i) { EditorGUI.BeginChangeCheck(); Quaternion newTargetRotation = Handles.RotationHandle(controlPointRotation.quaternionValue, controlPointPosition); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(LineData, "Change Spline Point Rotation"); controlPointRotation.quaternionValue = newTargetRotation; } } serializedObject.ApplyModifiedProperties(); } // Check for overlapping points OverlappingPointIndexes.Clear(); for (int i = 0; i < splineData.ControlPoints.Length; i++) { for (int j = 0; j < splineData.ControlPoints.Length; j++) { if (i == j) { continue; } if (Vector3.Distance(splineData.ControlPoints[i].Position, splineData.ControlPoints[j].Position) < OverlappingPointThreshold) { if (i != 0) { OverlappingPointIndexes.Add(i); } if (j != 0) { OverlappingPointIndexes.Add(j); } break; } } } }