GetLocalRectPoint() public static method

public static GetLocalRectPoint ( Rect rect, int index ) : Vector2
rect UnityEngine.Rect
index int
return Vector2
コード例 #1
0
ファイル: RectTool.cs プロジェクト: yaoya/UnityDecompiled
        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[] 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;
        }