protected override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { TransformManipulator.BeginManipulationHandling(false); EditorGUI.BeginChangeCheck(); // The AimConstraint changes the rotation of the active object as the object is moved around in the scene. // This leads to very large "jumps" of the object, // as the move tool assumes the handle rotation to not change while the object is dragged. // Solution: when moving an object constrained with the AimConstraint, we ignore the rotation of the object. Quaternion handleRotation = Tools.handleRotation; var aimConstraintComponent = Selection.activeTransform.GetComponent <UnityEngine.Animations.AimConstraint>(); if (aimConstraintComponent != null && aimConstraintComponent.constraintActive) { handleRotation = TransformManipulator.mouseDownHandleRotation; } Vector3 pos2 = Handles.PositionHandle(handlePosition, handleRotation); if (EditorGUI.EndChangeCheck() && !isStatic && TransformManipulator.HandleHasMoved(pos2)) { ManipulationToolUtility.SetMinDragDifferenceForPos(handlePosition); if (Tools.vertexDragging) { ManipulationToolUtility.DisableMinDragDifference(); } TransformManipulator.SetPositionDelta(pos2, TransformManipulator.mouseDownHandlePosition); } TransformManipulator.EndManipulationHandling(); }
protected override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { TransformManipulator.BeginManipulationHandling(false); EditorGUI.BeginChangeCheck(); Vector3 pos2 = Handles.PositionHandle(handlePosition, TransformManipulator.mouseDownHandleRotation); if (EditorGUI.EndChangeCheck() && !isStatic && TransformManipulator.HandleHasMoved(pos2)) { ManipulationToolUtility.SetMinDragDifferenceForPos(handlePosition); if (Tools.vertexDragging) { ManipulationToolUtility.DisableMinDragDifference(); } TransformManipulator.SetPositionDelta(pos2, TransformManipulator.mouseDownHandlePosition); } TransformManipulator.EndManipulationHandling(); }
public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { TransformManipulator.BeginManipulationHandling(false); EditorGUI.BeginChangeCheck(); Quaternion rotation = Tools.handleRotation; AimConstraint component = Selection.activeTransform.GetComponent <AimConstraint>(); if (component != null && component.constraintActive) { rotation = TransformManipulator.mouseDownHandleRotation; } Vector3 vector = Handles.PositionHandle(handlePosition, rotation); if (EditorGUI.EndChangeCheck() && !isStatic && TransformManipulator.HandleHasMoved(vector)) { ManipulationToolUtility.SetMinDragDifferenceForPos(handlePosition); if (Tools.vertexDragging) { ManipulationToolUtility.DisableMinDragDifference(); } TransformManipulator.SetPositionDelta(vector, TransformManipulator.mouseDownHandlePosition); } TransformManipulator.EndManipulationHandling(); }
protected override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { Rect rect = Tools.handleRect; Quaternion rectRotation = Tools.handleRectRotation; // Draw rect Vector3[] verts = new Vector3[4]; for (int i = 0; i < 4; i++) { Vector3 pos = GetLocalRectPoint(rect, i); verts[i] = rectRotation * pos + handlePosition; } RectHandles.RenderRectWithShadow(false, verts); // Handle fading Color oldColor = GUI.color; float faded = 1; if (Camera.current) { Vector3 viewDir = Camera.current.orthographic ? Camera.current.transform.forward : (handlePosition + rectRotation * rect.center - Camera.current.transform.position); Vector3 rectRight = rectRotation * Vector3.right * rect.width; Vector3 rectUp = rectRotation * Vector3.up * rect.height; float visibleSize = Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(rectRight, viewDir), Vector3.ProjectOnPlane(rectUp, viewDir)).magnitude); visibleSize /= HandleUtility.GetHandleSize(handlePosition); faded = Mathf.Clamp01((visibleSize - kMinVisibleSize) / kMinVisibleSize * 2); Color fadedColor = oldColor; fadedColor.a *= faded; GUI.color = fadedColor; } Vector3 oldPivot = Tools.cachedHandlePosition; // Pivot handle if (!Tools.vertexDragging) { RectTransform rectTransform = Selection.activeTransform.GetComponent <RectTransform>(); bool groupPivot = Selection.transforms.Length > 1; bool rectTransformPivot = !groupPivot && Tools.pivotMode == PivotMode.Pivot && rectTransform != null; using (new EditorGUI.DisabledScope(!groupPivot && !rectTransformPivot)) { EditorGUI.BeginChangeCheck(); Vector3 newPivot = PivotHandleGUI(rect, oldPivot, rectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { if (groupPivot) { Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (newPivot - oldPivot); } else if (rectTransformPivot) { Transform tr = Selection.activeTransform; Undo.RecordObject(rectTransform, "Move Rectangle Pivot"); Transform space = Tools.rectBlueprintMode && UnityEditorInternal.InternalEditorUtility.SupportsRectLayout(tr) ? tr.parent : tr; Vector2 offset = space.InverseTransformVector(newPivot - oldPivot); offset.x /= rectTransform.rect.width; offset.y /= rectTransform.rect.height; Vector2 pivot = rectTransform.pivot + offset; RectTransformEditor.SetPivotSmart(rectTransform, pivot.x, 0, true, space != rectTransform.transform); RectTransformEditor.SetPivotSmart(rectTransform, pivot.y, 1, true, space != rectTransform.transform); } } } } TransformManipulator.BeginManipulationHandling(true); if (!Tools.vertexDragging) { // Resize handles EditorGUI.BeginChangeCheck(); Vector3 scalePivot = handlePosition; Vector3 scale = ResizeHandlesGUI(rect, handlePosition, rectRotation, out scalePivot); if (EditorGUI.EndChangeCheck() && !isStatic) { TransformManipulator.SetResizeDelta(scale, scalePivot, rectRotation); } bool enableRotation = true; if (Tools.rectBlueprintMode) { foreach (Transform t in Selection.transforms) { if (t.GetComponent <RectTransform>() != null) { enableRotation = false; } } } if (enableRotation) { // Rotation handles EditorGUI.BeginChangeCheck(); Quaternion after = RotationHandlesGUI(rect, handlePosition, rectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { Quaternion delta = Quaternion.Inverse(rectRotation) * after; float angle; Vector3 axis; delta.ToAngleAxis(out angle, out axis); axis = rectRotation * axis; Undo.RecordObjects(Selection.transforms, "Rotate"); foreach (Transform t in Selection.transforms) { t.RotateAround(handlePosition, axis, angle); // 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 transform has non-uniformly scaled parent. } } Tools.handleRotation = Quaternion.AngleAxis(angle, axis) * Tools.handleRotation; } } } TransformManipulator.EndManipulationHandling(); TransformManipulator.BeginManipulationHandling(false); // Move handle EditorGUI.BeginChangeCheck(); Vector3 newPos = MoveHandlesGUI(rect, handlePosition, rectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { if (GridSnapping.active) { newPos = GridSnapping.Snap(newPos); } if (TransformManipulator.HandleHasMoved(newPos)) { TransformManipulator.SetPositionDelta(newPos, TransformManipulator.mouseDownHandlePosition); } } TransformManipulator.EndManipulationHandling(); GUI.color = oldColor; }
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) { Rect handleRect = Tools.handleRect; Quaternion handleRectRotation = Tools.handleRectRotation; Vector3[] array = new Vector3[4]; for (int i = 0; i < 4; i++) { Vector3 point = RectTool.GetLocalRectPoint(handleRect, i); array[i] = handleRectRotation * point + handlePosition; } RectHandles.RenderRectWithShadow(false, array); Color color = GUI.color; if (Camera.current) { Vector3 planeNormal = (!Camera.current.orthographic) ? (handlePosition + handleRectRotation * handleRect.center - Camera.current.transform.position) : Camera.current.transform.forward; Vector3 vector = handleRectRotation * Vector3.right * handleRect.width; Vector3 vector2 = handleRectRotation * Vector3.up * handleRect.height; float num = Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(vector, planeNormal), Vector3.ProjectOnPlane(vector2, planeNormal)).magnitude); num /= HandleUtility.GetHandleSize(handlePosition); float num2 = Mathf.Clamp01((num - 0.2f) / 0.2f * 2f); Color color2 = color; color2.a *= num2; GUI.color = color2; } Vector3 handlePosition2 = Tools.GetHandlePosition(); if (!Tools.vertexDragging) { RectTransform component = Selection.activeTransform.GetComponent <RectTransform>(); bool flag = Selection.transforms.Length > 1; bool flag2 = !flag && Tools.pivotMode == PivotMode.Pivot && component != null; using (new EditorGUI.DisabledScope(!flag && !flag2)) { EditorGUI.BeginChangeCheck(); Vector3 a = RectTool.PivotHandleGUI(handleRect, handlePosition2, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { if (flag) { Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (a - handlePosition2); } else if (flag2) { Transform activeTransform = Selection.activeTransform; Undo.RecordObject(component, "Move Rectangle Pivot"); Transform transform = (!Tools.rectBlueprintMode || !InternalEditorUtility.SupportsRectLayout(activeTransform)) ? activeTransform : activeTransform.parent; Vector2 b = transform.InverseTransformVector(a - handlePosition2); b.x /= component.rect.width; b.y /= component.rect.height; Vector2 vector3 = component.pivot + b; RectTransformEditor.SetPivotSmart(component, vector3.x, 0, true, transform != component.transform); RectTransformEditor.SetPivotSmart(component, vector3.y, 1, true, transform != component.transform); } } } } TransformManipulator.BeginManipulationHandling(true); if (!Tools.vertexDragging) { EditorGUI.BeginChangeCheck(); Vector3 pivotPosition = handlePosition; Vector3 scaleDelta = RectTool.ResizeHandlesGUI(handleRect, handlePosition, handleRectRotation, out pivotPosition); if (EditorGUI.EndChangeCheck() && !isStatic) { TransformManipulator.SetResizeDelta(scaleDelta, pivotPosition, handleRectRotation); } bool flag3 = true; if (Tools.rectBlueprintMode) { Transform[] transforms = Selection.transforms; for (int j = 0; j < transforms.Length; j++) { Transform transform2 = transforms[j]; if (transform2.GetComponent <RectTransform>() != null) { flag3 = false; } } } if (flag3) { EditorGUI.BeginChangeCheck(); Quaternion rhs = RectTool.RotationHandlesGUI(handleRect, handlePosition, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { float angle; Vector3 vector4; (Quaternion.Inverse(handleRectRotation) * rhs).ToAngleAxis(out angle, out vector4); vector4 = handleRectRotation * vector4; Undo.RecordObjects(Selection.transforms, "Rotate"); Transform[] transforms2 = Selection.transforms; for (int k = 0; k < transforms2.Length; k++) { Transform transform3 = transforms2[k]; transform3.RotateAround(handlePosition, vector4, angle); transform3.SetLocalEulerHint(transform3.GetLocalEulerAngles(transform3.rotationOrder)); if (transform3.parent != null) { transform3.SendTransformChangedScale(); } } Tools.handleRotation = Quaternion.AngleAxis(angle, vector4) * Tools.handleRotation; } } } TransformManipulator.EndManipulationHandling(); TransformManipulator.BeginManipulationHandling(false); EditorGUI.BeginChangeCheck(); Vector3 vector5 = RectTool.MoveHandlesGUI(handleRect, handlePosition, handleRectRotation); if (EditorGUI.EndChangeCheck() && !isStatic) { if (GridSnapping.active) { vector5 = GridSnapping.Snap(vector5); } if (TransformManipulator.HandleHasMoved(vector5)) { TransformManipulator.SetPositionDelta(vector5, TransformManipulator.mouseDownHandlePosition); } } TransformManipulator.EndManipulationHandling(); GUI.color = color; }
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(); }