Esempio n. 1
0
        private static Vector3 MoveHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            int     controlID = GUIUtility.GetControlID(RectTool.s_MoveHandleHash, FocusType.Passive);
            Vector3 vector    = pivot;
            float   num       = HandleUtility.GetHandleSize(pivot) * 0.2f;
            float   num2      = 1f - GUI.color.a;

            Vector3[] array = new Vector3[]
            {
                rotation *new Vector2(rect.x, rect.y) + pivot,
                rotation *new Vector2(rect.xMax, rect.y) + pivot,
                rotation *new Vector2(rect.xMax, rect.yMax) + pivot,
                rotation *new Vector2(rect.x, rect.yMax) + pivot
            };
            VertexSnapping.HandleKeyAndMouseMove(controlID);
            bool      flag           = Selection.transforms.Length == 1 && InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) && Selection.activeTransform.parent.rotation == rotation;
            Event     current        = Event.current;
            EventType typeForControl = current.GetTypeForControl(controlID);
            Plane     plane          = new Plane(array[0], array[1], array[2]);

            switch (typeForControl)
            {
            case EventType.MouseDown:
            {
                bool flag2 = Tools.vertexDragging || (current.button == 0 && current.modifiers == EventModifiers.None && RectHandles.RaycastGUIPointToWorldHit(current.mousePosition, plane, out RectTool.s_StartMouseWorldPos) && (RectTool.SceneViewDistanceToRectangle(array, current.mousePosition) == 0f || (num2 > 0f && RectTool.SceneViewDistanceToDisc(pivot, rotation * Vector3.forward, num, current.mousePosition) == 0f)));
                if (flag2)
                {
                    RectTool.s_StartPosition = pivot;
                    RectTool.s_StartMousePos = (RectTool.s_CurrentMousePos = current.mousePosition);
                    RectTool.s_Moving        = false;
                    RectTool.s_LockAxis      = -1;
                    int num3 = controlID;
                    GUIUtility.keyboardControl = num3;
                    GUIUtility.hotControl      = num3;
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    HandleUtility.ignoreRaySnapObjects = null;
                    current.Use();
                    if (flag)
                    {
                        Transform     activeTransform = Selection.activeTransform;
                        RectTransform component       = activeTransform.GetComponent <RectTransform>();
                        Transform     parent          = activeTransform.parent;
                        RectTransform component2      = parent.GetComponent <RectTransform>();
                        RectTool.s_StartRectPosition = component.anchoredPosition;
                        RectTransformSnapping.CalculatePositionSnapValues(parent, activeTransform, component2, component);
                    }
                }
                break;
            }

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    if (!RectTool.s_Moving)
                    {
                        Selection.activeGameObject = SceneViewPicking.PickGameObject(current.mousePosition);
                    }
                    GUIUtility.hotControl = 0;
                    EditorGUIUtility.SetWantsMouseJumping(0);
                    HandleUtility.ignoreRaySnapObjects = null;
                    current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    RectTool.s_CurrentMousePos += current.delta;
                    if (!RectTool.s_Moving && (RectTool.s_CurrentMousePos - RectTool.s_StartMousePos).magnitude > 3f)
                    {
                        RectTool.s_Moving = true;
                        RectHandles.RaycastGUIPointToWorldHit(RectTool.s_CurrentMousePos, plane, out RectTool.s_StartMouseWorldPos);
                    }
                    if (RectTool.s_Moving)
                    {
                        if (Tools.vertexDragging)
                        {
                            if (HandleUtility.ignoreRaySnapObjects == null)
                            {
                                Handles.SetupIgnoreRaySnapObjects();
                            }
                            Vector3 vector2;
                            if (HandleUtility.FindNearestVertex(RectTool.s_CurrentMousePos, null, out vector2))
                            {
                                vector      = vector2;
                                GUI.changed = true;
                            }
                            ManipulationToolUtility.minDragDifference = Vector2.zero;
                        }
                        else
                        {
                            ManipulationToolUtility.SetMinDragDifferenceForPos(pivot);
                            Vector3 a;
                            if (RectHandles.RaycastGUIPointToWorldHit(RectTool.s_CurrentMousePos, plane, out a))
                            {
                                Vector3 vector3 = a - RectTool.s_StartMouseWorldPos;
                                if (current.shift)
                                {
                                    vector3 = Quaternion.Inverse(rotation) * vector3;
                                    if (RectTool.s_LockAxis == -1)
                                    {
                                        RectTool.s_LockAxis = ((Mathf.Abs(vector3.x) <= Mathf.Abs(vector3.y)) ? 1 : 0);
                                    }
                                    vector3[1 - RectTool.s_LockAxis] = 0f;
                                    vector3 = rotation * vector3;
                                }
                                else
                                {
                                    RectTool.s_LockAxis = -1;
                                }
                                if (flag)
                                {
                                    Transform parent2 = Selection.activeTransform.parent;
                                    Vector3   vector4 = RectTool.s_StartRectPosition + parent2.InverseTransformVector(vector3);
                                    vector4.z = 0f;
                                    Quaternion rotation2    = Quaternion.Inverse(rotation);
                                    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 vector5 = RectTransformSnapping.SnapToGuides(vector4, snapDistance);
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(vector4, vector5);
                                    vector3 = parent2.TransformVector(vector5 - RectTool.s_StartRectPosition);
                                }
                                vector      = RectTool.s_StartPosition + vector3;
                                GUI.changed = true;
                            }
                        }
                    }
                    current.Use();
                }
                break;

            case EventType.Repaint:
                if (Tools.vertexDragging)
                {
                    RectHandles.RectScalingHandleCap(controlID, pivot, rotation, 1f, EventType.Repaint);
                }
                else
                {
                    Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 1.5f * num2);
                    Handles.CircleHandleCap(controlID, pivot, rotation, num, EventType.Repaint);
                    Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 0.3f * num2);
                    Handles.DrawSolidDisc(pivot, rotation * Vector3.forward, num);
                }
                break;
            }
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPosX", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingLeft", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingRight", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPosY", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingTop", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingBottom", typeForControl);
            return(vector);
        }
Esempio n. 2
0
        private static Vector3 MoveHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            int     controlId = GUIUtility.GetControlID(RectTool.s_MoveHandleHash, FocusType.Passive);
            Vector3 position  = pivot;
            float   num1      = HandleUtility.GetHandleSize(pivot) * 0.2f;
            float   num2      = 1f - GUI.color.a;

            Vector3[] worldPoints = new Vector3[4] {
                rotation *(Vector3) new Vector2(rect.x, rect.y) + pivot, rotation *(Vector3) new Vector2(rect.xMax, rect.y) + pivot, rotation *(Vector3) new Vector2(rect.xMax, rect.yMax) + pivot, rotation *(Vector3) new Vector2(rect.x, rect.yMax) + pivot
            };
            VertexSnapping.HandleKeyAndMouseMove(controlId);
            bool      flag           = Selection.transforms.Length == 1 && InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) && Selection.activeTransform.parent.rotation == rotation;
            Event     current        = Event.current;
            EventType typeForControl = current.GetTypeForControl(controlId);
            Plane     plane          = new Plane(worldPoints[0], worldPoints[1], worldPoints[2]);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (Tools.vertexDragging || current.button == 0 && current.modifiers == EventModifiers.None && RectHandles.RaycastGUIPointToWorldHit(current.mousePosition, plane, out RectTool.s_StartMouseWorldPos) && ((double)RectTool.SceneViewDistanceToRectangle(worldPoints, current.mousePosition) == 0.0 || (double)num2 > 0.0 && (double)RectTool.SceneViewDistanceToDisc(pivot, rotation * Vector3.forward, num1, current.mousePosition) == 0.0))
                {
                    RectTool.s_StartPosition = pivot;
                    RectTool.s_StartMousePos = RectTool.s_CurrentMousePos = current.mousePosition;
                    RectTool.s_Moving        = false;
                    RectTool.s_LockAxis      = -1;
                    int num3 = controlId;
                    GUIUtility.keyboardControl = num3;
                    GUIUtility.hotControl      = num3;
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    HandleUtility.ignoreRaySnapObjects = (Transform[])null;
                    current.Use();
                    if (flag)
                    {
                        Transform     activeTransform = Selection.activeTransform;
                        RectTransform component1      = activeTransform.GetComponent <RectTransform>();
                        Transform     parent          = activeTransform.parent;
                        RectTransform component2      = parent.GetComponent <RectTransform>();
                        RectTool.s_StartRectPosition = (Vector3)component1.anchoredPosition;
                        RectTransformSnapping.CalculatePositionSnapValues(parent, activeTransform, component2, component1);
                        break;
                    }
                    break;
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlId)
                {
                    if (!RectTool.s_Moving)
                    {
                        Selection.activeGameObject = SceneViewPicking.PickGameObject(current.mousePosition);
                    }
                    GUIUtility.hotControl = 0;
                    EditorGUIUtility.SetWantsMouseJumping(0);
                    HandleUtility.ignoreRaySnapObjects = (Transform[])null;
                    current.Use();
                    break;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlId)
                {
                    RectTool.s_CurrentMousePos += current.delta;
                    if (!RectTool.s_Moving && (double)(RectTool.s_CurrentMousePos - RectTool.s_StartMousePos).magnitude > 3.0)
                    {
                        RectTool.s_Moving = true;
                        RectHandles.RaycastGUIPointToWorldHit(RectTool.s_CurrentMousePos, plane, out RectTool.s_StartMouseWorldPos);
                    }
                    if (RectTool.s_Moving)
                    {
                        if (Tools.vertexDragging)
                        {
                            if (HandleUtility.ignoreRaySnapObjects == null)
                            {
                                Handles.SetupIgnoreRaySnapObjects();
                            }
                            Vector3 vertex;
                            if (HandleUtility.FindNearestVertex(RectTool.s_CurrentMousePos, (Transform[])null, out vertex))
                            {
                                position    = vertex;
                                GUI.changed = true;
                            }
                            ManipulationToolUtility.minDragDifference = (Vector3)Vector2.zero;
                        }
                        else
                        {
                            ManipulationToolUtility.SetMinDragDifferenceForPos(pivot);
                            Vector3 hit;
                            if (RectHandles.RaycastGUIPointToWorldHit(RectTool.s_CurrentMousePos, plane, out hit))
                            {
                                Vector3 vector = hit - RectTool.s_StartMouseWorldPos;
                                if (current.shift)
                                {
                                    vector = Quaternion.Inverse(rotation) * vector;
                                    if (RectTool.s_LockAxis == -1)
                                    {
                                        RectTool.s_LockAxis = (double)Mathf.Abs(vector.x) <= (double)Mathf.Abs(vector.y) ? 1 : 0;
                                    }
                                    vector[1 - RectTool.s_LockAxis] = 0.0f;
                                    vector = rotation * vector;
                                }
                                else
                                {
                                    RectTool.s_LockAxis = -1;
                                }
                                if (flag)
                                {
                                    Transform parent = Selection.activeTransform.parent;
                                    Vector3   positionBeforeSnapping = RectTool.s_StartRectPosition + parent.InverseTransformVector(vector);
                                    positionBeforeSnapping.z = 0.0f;
                                    Quaternion quaternion   = Quaternion.Inverse(rotation);
                                    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 guides = (Vector3)RectTransformSnapping.SnapToGuides((Vector2)positionBeforeSnapping, snapDistance);
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(positionBeforeSnapping, guides);
                                    vector = parent.TransformVector(guides - RectTool.s_StartRectPosition);
                                }
                                position    = RectTool.s_StartPosition + vector;
                                GUI.changed = true;
                            }
                        }
                    }
                    current.Use();
                    break;
                }
                break;

            case EventType.Repaint:
                if (Tools.vertexDragging)
                {
                    RectHandles.RectScalingCap(controlId, pivot, rotation, 1f);
                    break;
                }
                Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 1.5f * num2);
                Handles.CircleCap(controlId, pivot, rotation, num1);
                Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 0.3f * num2);
                Handles.DrawSolidDisc(pivot, rotation * Vector3.forward, num1);
                break;
            }
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPosX", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingLeft", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingRight", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPosY", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingTop", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingBottom", typeForControl);
            return(position);
        }