public static EventType EndManipulationHandling() { EventType usedEvent = EndEventCheck(); if (usedEvent == EventType.MouseDown) { RecordMouseDownState(Selection.transforms); s_StartHandlePosition = Tools.handlePosition; s_PreviousHandlePosition = s_StartHandlePosition; s_StartLocalHandleOffset = Tools.localHandleOffset; if (s_LockHandle) { Tools.LockHandlePosition(); } Tools.LockHandleRectRotation(); } else if (s_MouseDownState != null && (usedEvent == EventType.MouseUp || GUIUtility.hotControl != s_HotControl)) { s_StartHandleRotation = Tools.handleRotation; s_MouseDownState = null; if (s_LockHandle) { Tools.UnlockHandlePosition(); } Tools.UnlockHandleRectRotation(); ManipulationToolUtility.DisableMinDragDifference(); } return(usedEvent); }
public static EventType EndManipulationHandling() { EventType eventType = TransformManipulator.EndEventCheck(); if (eventType == EventType.MouseDown) { TransformManipulator.RecordMouseDownState(Selection.transforms); TransformManipulator.s_StartHandlePosition = Tools.handlePosition; TransformManipulator.s_StartLocalHandleOffset = Tools.localHandleOffset; if (TransformManipulator.s_LockHandle) { Tools.LockHandlePosition(); } Tools.LockHandleRectRotation(); } else if (TransformManipulator.s_MouseDownState != null && (eventType == EventType.MouseUp || GUIUtility.hotControl != TransformManipulator.s_HotControl)) { TransformManipulator.s_MouseDownState = null; if (TransformManipulator.s_LockHandle) { Tools.UnlockHandlePosition(); } Tools.UnlockHandleRectRotation(); ManipulationToolUtility.DisableMinDragDifference(); } return(eventType); }
protected override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { var ids = Handles.TransformHandleIds.Default; TransformManipulator.BeginManipulationHandling(false); // Lock position when scaling or rotating if (ids.scale.Has(GUIUtility.hotControl) || ids.rotation.Has(GUIUtility.hotControl)) { Tools.LockHandlePosition(); } else { Tools.UnlockHandlePosition(); } EditorGUI.BeginChangeCheck(); if (Event.current.type == EventType.MouseDown) { s_Scale = Vector3.one; } var startPosition = handlePosition; var endPosition = startPosition; var startRotation = Tools.handleRotation; var endRotation = startRotation; var startScale = s_Scale; var endScale = startScale; Handles.TransformHandle(ids, ref endPosition, ref endRotation, ref endScale, Handles.TransformHandleParam.Default); s_Scale = endScale; if (EditorGUI.EndChangeCheck() && !isStatic) { Undo.RecordObjects(Selection.transforms, "Transform Manipulation"); if (TransformManipulator.HandleHasMoved(endPosition)) { ManipulationToolUtility.SetMinDragDifferenceForPos(handlePosition); TransformManipulator.SetPositionDelta(endPosition, TransformManipulator.mouseDownHandlePosition); } Quaternion deltaRotation = Quaternion.Inverse(startRotation) * endRotation; float angle; Vector3 axis; deltaRotation.ToAngleAxis(out angle, out axis); if (!Mathf.Approximately(angle, 0)) { foreach (Transform t in Selection.transforms) { // Rotate around handlePosition (Global or Local axis). if (Tools.pivotMode == PivotMode.Center) { t.RotateAround(handlePosition, startRotation * axis, angle); } // Local rotation (Pivot mode with Local axis). else if (TransformManipulator.individualSpace) { t.Rotate(t.rotation * axis, angle, Space.World); } // Pivot mode with Global axis. else { t.Rotate(startRotation * axis, angle, Space.World); } // sync euler hints after a rotate tool update tyo fake continuous rotation t.SetLocalEulerHint(t.GetLocalEulerAngles(t.rotationOrder)); if (t.parent != null) { t.SendTransformChangedScale(); // force scale update, needed if tr has non-uniformly scaled parent. } } Tools.handleRotation = endRotation; } if (endScale != startScale) { TransformManipulator.SetScaleDelta(endScale, endRotation); } } TransformManipulator.EndManipulationHandling(); }
public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { Handles.TransformHandleIds @default = Handles.TransformHandleIds.Default; TransformManipulator.BeginManipulationHandling(false); if (@default.scale.Has(GUIUtility.hotControl) || @default.rotation.Has(GUIUtility.hotControl)) { Tools.LockHandlePosition(); } else { Tools.UnlockHandlePosition(); } EditorGUI.BeginChangeCheck(); if (Event.current.type == EventType.MouseDown) { TransformTool.s_Scale = Vector3.one; } Vector3 vector = handlePosition; Quaternion handleRotation = Tools.handleRotation; Quaternion quaternion = handleRotation; Vector3 vector2 = TransformTool.s_Scale; Vector3 vector3 = vector2; Handles.TransformHandle(@default, ref vector, ref quaternion, ref vector3, Handles.TransformHandleParam.Default); TransformTool.s_Scale = vector3; if (EditorGUI.EndChangeCheck() && !isStatic) { Undo.RecordObjects(Selection.transforms, "Transform Manipulation"); if (TransformManipulator.HandleHasMoved(vector)) { ManipulationToolUtility.SetMinDragDifferenceForPos(handlePosition); TransformManipulator.SetPositionDelta(vector, TransformManipulator.mouseDownHandlePosition); } float num; Vector3 point; (Quaternion.Inverse(handleRotation) * quaternion).ToAngleAxis(out num, out point); if (!Mathf.Approximately(num, 0f)) { Transform[] transforms = Selection.transforms; for (int i = 0; i < transforms.Length; i++) { Transform transform = transforms[i]; if (Tools.pivotMode == PivotMode.Center) { transform.RotateAround(handlePosition, handleRotation * point, num); } else if (TransformManipulator.individualSpace) { transform.Rotate(transform.rotation * point, num, Space.World); } else { transform.Rotate(handleRotation * point, num, Space.World); } transform.SetLocalEulerHint(transform.GetLocalEulerAngles(transform.rotationOrder)); if (transform.parent != null) { transform.SendTransformChangedScale(); } } Tools.handleRotation = quaternion; } if (vector3 != vector2) { TransformManipulator.SetScaleDelta(vector3, quaternion); } } TransformManipulator.EndManipulationHandling(); }