GetRectPointInWorld() private static method

private static GetRectPointInWorld ( Rect rect, Vector3 pivot, Quaternion rotation, int xHandle, int yHandle ) : Vector3
rect UnityEngine.Rect
pivot Vector3
rotation UnityEngine.Quaternion
xHandle int
yHandle int
return Vector3
Ejemplo n.º 1
0
        private static Quaternion RotationHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            Vector3 eulerAngles = rotation.eulerAngles;

            for (int i = 0; i <= 2; i += 2)
            {
                for (int j = 0; j <= 2; j += 2)
                {
                    Vector3 rectPointInWorld = RectTool.GetRectPointInWorld(rect, pivot, rotation, i, j);
                    float   handleSize       = 0.05f * HandleUtility.GetHandleSize(rectPointInWorld);
                    int     controlID        = GUIUtility.GetControlID(RectTool.s_RotationHandlesHash, FocusType.Passive);
                    if (GUI.color.a > 0f || GUIUtility.hotControl == controlID)
                    {
                        EditorGUI.BeginChangeCheck();
                        Vector3 outwardsDir  = rotation * Vector3.right * (float)(i - 1);
                        Vector3 outwardsDir2 = rotation * Vector3.up * (float)(j - 1);
                        float   num          = RectHandles.RotationSlider(controlID, rectPointInWorld, eulerAngles.z, pivot, rotation * Vector3.forward, outwardsDir, outwardsDir2, handleSize, null, Vector2.zero);
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (Event.current.shift)
                            {
                                num = Mathf.Round((num - eulerAngles.z) / 15f) * 15f + eulerAngles.z;
                            }
                            eulerAngles.z = num;
                            rotation      = Quaternion.Euler(eulerAngles);
                        }
                    }
                }
            }
            return(rotation);
        }
Ejemplo n.º 2
0
        private static Quaternion RotationHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            Vector3 eulerAngles = rotation.eulerAngles;
            int     xHandle     = 0;

            while (xHandle <= 2)
            {
                int yHandle = 0;
                while (yHandle <= 2)
                {
                    Vector3 rectPointInWorld = RectTool.GetRectPointInWorld(rect, pivot, rotation, xHandle, yHandle);
                    float   handleSize       = 0.05f * HandleUtility.GetHandleSize(rectPointInWorld);
                    int     controlId        = GUIUtility.GetControlID(RectTool.s_RotationHandlesHash, FocusType.Passive);
                    if ((double)GUI.color.a > 0.0 || GUIUtility.hotControl == controlId)
                    {
                        EditorGUI.BeginChangeCheck();
                        Vector3 outwardsDir1 = rotation * Vector3.right * (float)(xHandle - 1);
                        Vector3 outwardsDir2 = rotation * Vector3.up * (float)(yHandle - 1);
                        float   num          = RectHandles.RotationSlider(controlId, rectPointInWorld, eulerAngles.z, pivot, rotation * Vector3.forward, outwardsDir1, outwardsDir2, handleSize, (Handles.DrawCapFunction)null, Vector2.zero);
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (Event.current.shift)
                            {
                                num = Mathf.Round((float)(((double)num - (double)eulerAngles.z) / 15.0)) * 15f + eulerAngles.z;
                            }
                            eulerAngles.z = num;
                            rotation      = Quaternion.Euler(eulerAngles);
                        }
                    }
                    yHandle += 2;
                }
                xHandle += 2;
            }
            return(rotation);
        }
Ejemplo n.º 3
0
        private static Vector3 ResizeHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation, out Vector3 scalePivot)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                RectTool.s_StartRect = rect;
            }
            scalePivot = pivot;
            Vector3    result    = Vector3.one;
            Quaternion rotation2 = Quaternion.Inverse(rotation);

            for (int i = 0; i <= 2; i++)
            {
                for (int j = 0; j <= 2; j++)
                {
                    if (i != 1 || j != 1)
                    {
                        Vector3 rectPointInWorld  = RectTool.GetRectPointInWorld(RectTool.s_StartRect, pivot, rotation, i, j);
                        Vector3 rectPointInWorld2 = RectTool.GetRectPointInWorld(rect, pivot, rotation, i, j);
                        float   num       = 0.05f * HandleUtility.GetHandleSize(rectPointInWorld2);
                        int     controlID = GUIUtility.GetControlID(RectTool.s_ResizeHandlesHash, FocusType.Passive);
                        if (GUI.color.a > 0f || GUIUtility.hotControl == controlID)
                        {
                            EditorGUI.BeginChangeCheck();
                            EventType type = Event.current.type;
                            Vector3   vector;
                            if (i == 1 || j == 1)
                            {
                                Vector3 sideVector = (i != 1) ? (rotation * Vector3.up * rect.height) : (rotation * Vector3.right * rect.width);
                                Vector3 direction  = (i != 1) ? (rotation * Vector3.right) : (rotation * Vector3.up);
                                vector = RectHandles.SideSlider(controlID, rectPointInWorld2, sideVector, direction, num, null, 0f);
                            }
                            else
                            {
                                Vector3 vector2   = rotation * Vector3.right * (float)(i - 1);
                                Vector3 vector3   = rotation * Vector3.up * (float)(j - 1);
                                int     arg_1AB_0 = controlID;
                                Vector3 arg_1AB_1 = rectPointInWorld2;
                                Vector3 arg_1AB_2 = rotation * Vector3.forward;
                                Vector3 arg_1AB_3 = vector2;
                                Vector3 arg_1AB_4 = vector3;
                                float   arg_1AB_5 = num;
                                if (RectTool.< > f__mg$cache0 == null)
                                {
                                    RectTool.< > f__mg$cache0 = new Handles.CapFunction(RectHandles.RectScalingHandleCap);
                                }
                                vector = RectHandles.CornerSlider(arg_1AB_0, arg_1AB_1, arg_1AB_2, arg_1AB_3, arg_1AB_4, arg_1AB_5, RectTool.< > f__mg$cache0, Vector2.zero);
                            }
                            bool flag = Selection.transforms.Length == 1 && InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) && Selection.activeTransform.parent.rotation == rotation;
                            if (flag)
                            {
                                Transform     activeTransform = Selection.activeTransform;
                                RectTransform component       = activeTransform.GetComponent <RectTransform>();
                                Transform     parent          = activeTransform.parent;
                                RectTransform component2      = parent.GetComponent <RectTransform>();
                                if (type == EventType.MouseDown && Event.current.type != EventType.MouseDown)
                                {
                                    RectTransformSnapping.CalculateOffsetSnapValues(parent, activeTransform, component2, component, i, j);
                                }
                            }
                            if (EditorGUI.EndChangeCheck())
                            {
                                ManipulationToolUtility.SetMinDragDifferenceForPos(rectPointInWorld2, 0.1f);
                                if (flag)
                                {
                                    Transform     parent2      = Selection.activeTransform.parent;
                                    RectTransform component3   = parent2.GetComponent <RectTransform>();
                                    Vector2       snapDistance = Vector2.one * HandleUtility.GetHandleSize(vector) * 0.05f;
                                    snapDistance.x /= (rotation2 * parent2.TransformVector(Vector3.right)).x;
                                    snapDistance.y /= (rotation2 * parent2.TransformVector(Vector3.up)).y;
                                    Vector3 vector4 = parent2.InverseTransformPoint(vector) - component3.rect.min;
                                    Vector3 vector5 = RectTransformSnapping.SnapToGuides(vector4, snapDistance) + Vector3.forward * vector4.z;
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(vector4, vector5);
                                    vector = parent2.TransformPoint(vector5 + component3.rect.min);
                                }
                                bool alt       = Event.current.alt;
                                bool actionKey = EditorGUI.actionKey;
                                bool flag2     = Event.current.shift && !actionKey;
                                if (!alt)
                                {
                                    scalePivot = RectTool.GetRectPointInWorld(RectTool.s_StartRect, pivot, rotation, 2 - i, 2 - j);
                                }
                                if (flag2)
                                {
                                    vector = Vector3.Project(vector - scalePivot, rectPointInWorld - scalePivot) + scalePivot;
                                }
                                Vector3 vector6 = rotation2 * (rectPointInWorld - scalePivot);
                                Vector3 vector7 = rotation2 * (vector - scalePivot);
                                if (i != 1)
                                {
                                    result.x = vector7.x / vector6.x;
                                }
                                if (j != 1)
                                {
                                    result.y = vector7.y / vector6.y;
                                }
                                if (flag2)
                                {
                                    float d = (i != 1) ? result.x : result.y;
                                    result = Vector3.one * d;
                                }
                                if (actionKey && i == 1)
                                {
                                    if (Event.current.shift)
                                    {
                                        result.x = (result.z = 1f / Mathf.Sqrt(Mathf.Max(result.y, 0.0001f)));
                                    }
                                    else
                                    {
                                        result.x = 1f / Mathf.Max(result.y, 0.0001f);
                                    }
                                }
                                if (flag2)
                                {
                                    float d2 = (i != 1) ? result.x : result.y;
                                    result = Vector3.one * d2;
                                }
                                if (actionKey && i == 1)
                                {
                                    if (Event.current.shift)
                                    {
                                        result.x = (result.z = 1f / Mathf.Sqrt(Mathf.Max(result.y, 0.0001f)));
                                    }
                                    else
                                    {
                                        result.x = 1f / Mathf.Max(result.y, 0.0001f);
                                    }
                                }
                                if (actionKey && j == 1)
                                {
                                    if (Event.current.shift)
                                    {
                                        result.y = (result.z = 1f / Mathf.Sqrt(Mathf.Max(result.x, 0.0001f)));
                                    }
                                    else
                                    {
                                        result.y = 1f / Mathf.Max(result.x, 0.0001f);
                                    }
                                }
                            }
                            if (i == 0)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingLeft", type);
                            }
                            if (i == 2)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingRight", type);
                            }
                            if (i != 1)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingWidth", type);
                            }
                            if (j == 0)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingBottom", type);
                            }
                            if (j == 2)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingTop", type);
                            }
                            if (j != 1)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingHeight", type);
                            }
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        private static Vector3 ResizeHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation, out Vector3 scalePivot)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                RectTool.s_StartRect = rect;
            }
            scalePivot = pivot;
            Vector3    vector3_1  = Vector3.one;
            Quaternion quaternion = Quaternion.Inverse(rotation);

            for (int xHandle = 0; xHandle <= 2; ++xHandle)
            {
                for (int yHandle = 0; yHandle <= 2; ++yHandle)
                {
                    if (xHandle != 1 || yHandle != 1)
                    {
                        Vector3 rectPointInWorld1 = RectTool.GetRectPointInWorld(RectTool.s_StartRect, pivot, rotation, xHandle, yHandle);
                        Vector3 rectPointInWorld2 = RectTool.GetRectPointInWorld(rect, pivot, rotation, xHandle, yHandle);
                        float   num       = 0.05f * HandleUtility.GetHandleSize(rectPointInWorld2);
                        int     controlId = GUIUtility.GetControlID(RectTool.s_ResizeHandlesHash, FocusType.Passive);
                        if ((double)GUI.color.a > 0.0 || GUIUtility.hotControl == controlId)
                        {
                            EditorGUI.BeginChangeCheck();
                            EventType type = Event.current.type;
                            Vector3   position;
                            if (xHandle == 1 || yHandle == 1)
                            {
                                Vector3 sideVector = xHandle != 1 ? rotation * Vector3.up * rect.height : rotation * Vector3.right * rect.width;
                                Vector3 direction  = xHandle != 1 ? rotation * Vector3.right : rotation * Vector3.up;
                                position = RectHandles.SideSlider(controlId, rectPointInWorld2, sideVector, direction, num, (Handles.DrawCapFunction)null, 0.0f);
                            }
                            else
                            {
                                Vector3 outwardsDir1 = rotation * Vector3.right * (float)(xHandle - 1);
                                Vector3 outwardsDir2 = rotation * Vector3.up * (float)(yHandle - 1);
                                position = RectHandles.CornerSlider(controlId, rectPointInWorld2, rotation * Vector3.forward, outwardsDir1, outwardsDir2, num, new Handles.DrawCapFunction(RectHandles.RectScalingCap), Vector2.zero);
                            }
                            bool flag1 = Selection.transforms.Length == 1 && InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) && Selection.activeTransform.parent.rotation == rotation;
                            if (flag1)
                            {
                                Transform     activeTransform = Selection.activeTransform;
                                RectTransform component1      = activeTransform.GetComponent <RectTransform>();
                                Transform     parent          = activeTransform.parent;
                                RectTransform component2      = parent.GetComponent <RectTransform>();
                                if (type == EventType.MouseDown && Event.current.type != EventType.MouseDown)
                                {
                                    RectTransformSnapping.CalculateOffsetSnapValues(parent, activeTransform, component2, component1, xHandle, yHandle);
                                }
                            }
                            if (EditorGUI.EndChangeCheck())
                            {
                                ManipulationToolUtility.SetMinDragDifferenceForPos(rectPointInWorld2);
                                if (flag1)
                                {
                                    Transform     parent       = Selection.activeTransform.parent;
                                    RectTransform component    = parent.GetComponent <RectTransform>();
                                    Vector2       snapDistance = Vector2.one * HandleUtility.GetHandleSize(position) * 0.05f;
                                    snapDistance.x /= (quaternion * parent.TransformVector(Vector3.right)).x;
                                    snapDistance.y /= (quaternion * parent.TransformVector(Vector3.up)).y;
                                    Vector3 positionBeforeSnapping = parent.InverseTransformPoint(position) - (Vector3)component.rect.min;
                                    Vector3 positionAfterSnapping  = (Vector3)RectTransformSnapping.SnapToGuides((Vector2)positionBeforeSnapping, snapDistance) + Vector3.forward * positionBeforeSnapping.z;
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(positionBeforeSnapping, positionAfterSnapping);
                                    position = parent.TransformPoint(positionAfterSnapping + (Vector3)component.rect.min);
                                }
                                bool alt       = Event.current.alt;
                                bool actionKey = EditorGUI.actionKey;
                                bool flag2     = Event.current.shift && !actionKey;
                                if (!alt)
                                {
                                    scalePivot = RectTool.GetRectPointInWorld(RectTool.s_StartRect, pivot, rotation, 2 - xHandle, 2 - yHandle);
                                }
                                if (flag2)
                                {
                                    position = Vector3.Project(position - scalePivot, rectPointInWorld1 - scalePivot) + scalePivot;
                                }
                                Vector3 vector3_2 = quaternion * (rectPointInWorld1 - scalePivot);
                                Vector3 vector3_3 = quaternion * (position - scalePivot);
                                if (xHandle != 1)
                                {
                                    vector3_1.x = vector3_3.x / vector3_2.x;
                                }
                                if (yHandle != 1)
                                {
                                    vector3_1.y = vector3_3.y / vector3_2.y;
                                }
                                if (flag2)
                                {
                                    vector3_1 = Vector3.one * (xHandle != 1 ? vector3_1.x : vector3_1.y);
                                }
                                if (actionKey && xHandle == 1)
                                {
                                    vector3_1.x = !Event.current.shift ? 1f / Mathf.Max(vector3_1.y, 0.0001f) : (vector3_1.z = 1f / Mathf.Sqrt(Mathf.Max(vector3_1.y, 0.0001f)));
                                }
                                if (flag2)
                                {
                                    vector3_1 = Vector3.one * (xHandle != 1 ? vector3_1.x : vector3_1.y);
                                }
                                if (actionKey && xHandle == 1)
                                {
                                    vector3_1.x = !Event.current.shift ? 1f / Mathf.Max(vector3_1.y, 0.0001f) : (vector3_1.z = 1f / Mathf.Sqrt(Mathf.Max(vector3_1.y, 0.0001f)));
                                }
                                if (actionKey && yHandle == 1)
                                {
                                    vector3_1.y = !Event.current.shift ? 1f / Mathf.Max(vector3_1.x, 0.0001f) : (vector3_1.z = 1f / Mathf.Sqrt(Mathf.Max(vector3_1.x, 0.0001f)));
                                }
                            }
                            if (xHandle == 0)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingLeft", type);
                            }
                            if (xHandle == 2)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingRight", type);
                            }
                            if (xHandle != 1)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingWidth", type);
                            }
                            if (yHandle == 0)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingBottom", type);
                            }
                            if (yHandle == 2)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingTop", type);
                            }
                            if (yHandle != 1)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingHeight", type);
                            }
                        }
                    }
                }
            }
            return(vector3_1);
        }