GetHandlePosition() static private method

static private GetHandlePosition ( ) : Vector3
return Vector3
示例#1
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;
        }
示例#2
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;
        }
示例#3
0
        public 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.GetHandlePosition();

            // 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;
        }
示例#4
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;
        }