SetPositionDelta() public static method

public static SetPositionDelta ( Vector3 positionDelta ) : void
positionDelta Vector3
return void
        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();
        }
Example #2
0
        public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic)
        {
            TransformManipulator.BeginManipulationHandling(false);
            EditorGUI.BeginChangeCheck();
            Vector3 vector = Handles.PositionHandle(handlePosition, Tools.handleRotation);

            if (EditorGUI.EndChangeCheck() && !isStatic)
            {
                Vector3 positionDelta = vector - TransformManipulator.mouseDownHandlePosition;
                ManipulationToolUtility.SetMinDragDifferenceForPos(handlePosition);
                TransformManipulator.SetPositionDelta(positionDelta);
            }
            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();
        }
Example #4
0
        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();
        }
Example #7
0
        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;
        }
Example #8
0
        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();
        }
Example #9
0
        public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic)
        {
            Rect       handleRect         = Tools.handleRect;
            Quaternion handleRectRotation = Tools.handleRectRotation;

            Vector3[] corners = new Vector3[4];
            for (int i = 0; i < 4; i++)
            {
                Vector3 localRectPoint = (Vector3)GetLocalRectPoint(handleRect, i);
                corners[i] = ((Vector3)(handleRectRotation * localRectPoint)) + handlePosition;
            }
            RectHandles.RenderRectWithShadow(false, corners);
            Color color = GUI.color;
            float num2  = 1f;

            if (Camera.current != null)
            {
                Vector3 planeNormal = !Camera.current.orthographic ? ((handlePosition + (handleRectRotation * handleRect.center)) - Camera.current.transform.position) : Camera.current.transform.forward;
                Vector3 vector      = (Vector3)((handleRectRotation * Vector3.right) * handleRect.width);
                Vector3 vector4     = (Vector3)((handleRectRotation * Vector3.up) * handleRect.height);
                float   num3        = Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(vector, planeNormal), Vector3.ProjectOnPlane(vector4, planeNormal)).magnitude) / HandleUtility.GetHandleSize(handlePosition);
                num2 = Mathf.Clamp01(((num3 - 0.2f) / 0.2f) * 2f);
                Color color2 = color;
                color2.a *= num2;
                GUI.color = color2;
            }
            Vector3 pivot = 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);
                EditorGUI.BeginDisabledGroup(!flag && !flag2);
                EditorGUI.BeginChangeCheck();
                Vector3 vector6 = PivotHandleGUI(handleRect, pivot, handleRectRotation);
                if (EditorGUI.EndChangeCheck() && !isStatic)
                {
                    if (flag)
                    {
                        Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (vector6 - pivot);
                    }
                    else if (flag2)
                    {
                        Transform activeTransform = Selection.activeTransform;
                        Undo.RecordObject(component, "Move Rectangle Pivot");
                        Transform transform3 = (!Tools.rectBlueprintMode || !InternalEditorUtility.SupportsRectLayout(activeTransform)) ? activeTransform : activeTransform.parent;
                        Vector2   vector7    = transform3.InverseTransformVector(vector6 - pivot);
                        vector7.x /= component.rect.width;
                        vector7.y /= component.rect.height;
                        Vector2 vector8 = component.pivot + vector7;
                        RectTransformEditor.SetPivotSmart(component, vector8.x, 0, true, transform3 != component.transform);
                        RectTransformEditor.SetPivotSmart(component, vector8.y, 1, true, transform3 != component.transform);
                    }
                }
                EditorGUI.EndDisabledGroup();
            }
            TransformManipulator.BeginManipulationHandling(true);
            if (!Tools.vertexDragging)
            {
                EditorGUI.BeginChangeCheck();
                Vector3 scalePivot = handlePosition;
                Vector3 scaleDelta = ResizeHandlesGUI(handleRect, handlePosition, handleRectRotation, out scalePivot);
                if (EditorGUI.EndChangeCheck() && !isStatic)
                {
                    TransformManipulator.SetResizeDelta(scaleDelta, scalePivot, handleRectRotation);
                }
                bool flag3 = true;
                if (Tools.rectBlueprintMode)
                {
                    foreach (Transform transform4 in Selection.transforms)
                    {
                        if (transform4.GetComponent <RectTransform>() != null)
                        {
                            flag3 = false;
                        }
                    }
                }
                if (flag3)
                {
                    EditorGUI.BeginChangeCheck();
                    Quaternion quaternion2 = RotationHandlesGUI(handleRect, handlePosition, handleRectRotation);
                    if (EditorGUI.EndChangeCheck() && !isStatic)
                    {
                        float   num5;
                        Vector3 vector11;
                        (Quaternion.Inverse(handleRectRotation) * quaternion2).ToAngleAxis(out num5, out vector11);
                        vector11 = (Vector3)(handleRectRotation * vector11);
                        Undo.RecordObjects(Selection.transforms, "Rotate");
                        foreach (Transform transform5 in Selection.transforms)
                        {
                            transform5.RotateAround(handlePosition, vector11, num5);
                            if (transform5.parent != null)
                            {
                                transform5.SendTransformChangedScale();
                            }
                        }
                        Tools.handleRotation = Quaternion.AngleAxis(num5, vector11) * Tools.handleRotation;
                    }
                }
            }
            TransformManipulator.EndManipulationHandling();
            TransformManipulator.BeginManipulationHandling(false);
            EditorGUI.BeginChangeCheck();
            Vector3 vector12 = MoveHandlesGUI(handleRect, handlePosition, handleRectRotation);

            if (EditorGUI.EndChangeCheck() && !isStatic)
            {
                Vector3 positionDelta = vector12 - TransformManipulator.mouseDownHandlePosition;
                TransformManipulator.SetPositionDelta(positionDelta);
            }
            TransformManipulator.EndManipulationHandling();
            GUI.color = color;
        }
Example #10
0
        public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic)
        {
            Rect       handleRect         = Tools.handleRect;
            Quaternion handleRectRotation = Tools.handleRectRotation;

            Vector3[] vector3Array = new Vector3[4];
            for (int index = 0; index < 4; ++index)
            {
                Vector3 localRectPoint = (Vector3)RectTool.GetLocalRectPoint(handleRect, index);
                vector3Array[index] = handleRectRotation * localRectPoint + handlePosition;
            }
            RectHandles.RenderRectWithShadow(false, vector3Array);
            Color color1 = GUI.color;

            if ((bool)((Object)Camera.current))
            {
                Vector3 planeNormal = !Camera.current.orthographic ? handlePosition + handleRectRotation * (Vector3)handleRect.center - Camera.current.transform.position : Camera.current.transform.forward;
                Vector3 vector1     = handleRectRotation * Vector3.right * handleRect.width;
                Vector3 vector2     = handleRectRotation * Vector3.up * handleRect.height;
                float   num         = Mathf.Clamp01((float)(((double)(Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(vector1, planeNormal), Vector3.ProjectOnPlane(vector2, planeNormal)).magnitude) / HandleUtility.GetHandleSize(handlePosition)) - 0.200000002980232) / 0.200000002980232 * 2.0));
                Color   color2      = color1;
                color2.a *= num;
                GUI.color = color2;
            }
            Vector3 handlePosition1 = Tools.GetHandlePosition();

            if (!Tools.vertexDragging)
            {
                RectTransform component = Selection.activeTransform.GetComponent <RectTransform>();
                bool          flag1     = Selection.transforms.Length > 1;
                bool          flag2     = !flag1 && Tools.pivotMode == PivotMode.Pivot && (Object)component != (Object)null;
                EditorGUI.BeginDisabledGroup(!flag1 && !flag2);
                EditorGUI.BeginChangeCheck();
                Vector3 vector3 = RectTool.PivotHandleGUI(handleRect, handlePosition1, handleRectRotation);
                if (EditorGUI.EndChangeCheck() && !isStatic)
                {
                    if (flag1)
                    {
                        Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (vector3 - handlePosition1);
                    }
                    else if (flag2)
                    {
                        Transform activeTransform = Selection.activeTransform;
                        Undo.RecordObject((Object)component, "Move Rectangle Pivot");
                        Transform transform = !Tools.rectBlueprintMode || !InternalEditorUtility.SupportsRectLayout(activeTransform) ? activeTransform : activeTransform.parent;
                        Vector2   vector2_1 = (Vector2)transform.InverseTransformVector(vector3 - handlePosition1);
                        vector2_1.x /= component.rect.width;
                        vector2_1.y /= component.rect.height;
                        Vector2 vector2_2 = component.pivot + vector2_1;
                        RectTransformEditor.SetPivotSmart(component, vector2_2.x, 0, true, (Object)transform != (Object)component.transform);
                        RectTransformEditor.SetPivotSmart(component, vector2_2.y, 1, true, (Object)transform != (Object)component.transform);
                    }
                }
                EditorGUI.EndDisabledGroup();
            }
            TransformManipulator.BeginManipulationHandling(true);
            if (!Tools.vertexDragging)
            {
                EditorGUI.BeginChangeCheck();
                Vector3 scalePivot = handlePosition;
                Vector3 scaleDelta = RectTool.ResizeHandlesGUI(handleRect, handlePosition, handleRectRotation, out scalePivot);
                if (EditorGUI.EndChangeCheck() && !isStatic)
                {
                    TransformManipulator.SetResizeDelta(scaleDelta, scalePivot, handleRectRotation);
                }
                bool flag = true;
                if (Tools.rectBlueprintMode)
                {
                    foreach (Component transform in Selection.transforms)
                    {
                        if ((Object)transform.GetComponent <RectTransform>() != (Object)null)
                        {
                            flag = false;
                        }
                    }
                }
                if (flag)
                {
                    EditorGUI.BeginChangeCheck();
                    Quaternion quaternion = RectTool.RotationHandlesGUI(handleRect, handlePosition, handleRectRotation);
                    if (EditorGUI.EndChangeCheck() && !isStatic)
                    {
                        float   angle;
                        Vector3 axis1;
                        (Quaternion.Inverse(handleRectRotation) * quaternion).ToAngleAxis(out angle, out axis1);
                        Vector3 axis2 = handleRectRotation * axis1;
                        Undo.RecordObjects((Object[])Selection.transforms, "Rotate");
                        foreach (Transform transform in Selection.transforms)
                        {
                            transform.RotateAround(handlePosition, axis2, angle);
                            if ((Object)transform.parent != (Object)null)
                            {
                                transform.SendTransformChangedScale();
                            }
                        }
                        Tools.handleRotation = Quaternion.AngleAxis(angle, axis2) * Tools.handleRotation;
                    }
                }
            }
            int num1 = (int)TransformManipulator.EndManipulationHandling();

            TransformManipulator.BeginManipulationHandling(false);
            EditorGUI.BeginChangeCheck();
            Vector3 vector3_1 = RectTool.MoveHandlesGUI(handleRect, handlePosition, handleRectRotation);

            if (EditorGUI.EndChangeCheck() && !isStatic)
            {
                TransformManipulator.SetPositionDelta(vector3_1 - TransformManipulator.mouseDownHandlePosition);
            }
            int num2 = (int)TransformManipulator.EndManipulationHandling();

            GUI.color = color1;
        }