PickGameObject() public static méthode

public static PickGameObject ( Vector2 mousePosition ) : GameObject
mousePosition Vector2
Résultat UnityEngine.GameObject
        static Vector3 MoveHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            int id = GUIUtility.GetControlID(s_MoveHandleHash, FocusType.Passive);

            Vector3 newPos      = pivot;
            float   discSize    = HandleUtility.GetHandleSize(pivot) * 0.2f;
            float   discOpacity = (1 - GUI.color.a);

            Vector3[] corners = new Vector3[4];
            corners[0] = rotation * new Vector2(rect.x, rect.y) + pivot;
            corners[1] = rotation * new Vector2(rect.xMax, rect.y) + pivot;
            corners[2] = rotation * new Vector2(rect.xMax, rect.yMax) + pivot;
            corners[3] = rotation * new Vector2(rect.x, rect.yMax) + pivot;

            VertexSnapping.HandleMouseMove(id);

            bool supportsRectSnapping = Selection.transforms.Length == 1 &&
                                        UnityEditorInternal.InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) &&
                                        Selection.activeTransform.parent.rotation == rotation;

            Event     evt       = Event.current;
            EventType eventType = evt.GetTypeForControl(id);
            Plane     guiPlane  = new Plane(corners[0], corners[1], corners[2]);

            switch (eventType)
            {
            case EventType.MouseDown:
            {
                bool acceptClick = false;

                if (Tools.vertexDragging)
                {
                    acceptClick = true;
                }
                else
                {
                    acceptClick =
                        evt.button == 0 &&
                        evt.modifiers == 0 &&
                        RectHandles.RaycastGUIPointToWorldHit(evt.mousePosition, guiPlane, out s_StartMouseWorldPos) &&
                        (
                            SceneViewDistanceToRectangle(corners, evt.mousePosition) == 0f ||
                            (discOpacity > 0 && SceneViewDistanceToDisc(pivot, rotation * Vector3.forward, discSize, evt.mousePosition) == 0f)
                        );
                }

                if (acceptClick)
                {
                    s_StartPosition       = pivot;
                    s_StartMousePos       = s_CurrentMousePos = evt.mousePosition;
                    s_Moving              = false;
                    s_LockAxis            = -1;
                    GUIUtility.hotControl = GUIUtility.keyboardControl = id;
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    HandleUtility.ignoreRaySnapObjects = null;
                    evt.Use();

                    // Calculate snapping values if applicable
                    if (supportsRectSnapping)
                    {
                        Transform     transform           = Selection.activeTransform;
                        RectTransform rectTransform       = transform.GetComponent <RectTransform>();
                        Transform     transformParent     = transform.parent;
                        RectTransform rectTransformParent = transformParent.GetComponent <RectTransform>();

                        s_StartRectPosition = rectTransform.anchoredPosition;

                        RectTransformSnapping.CalculatePositionSnapValues(transformParent, transform, rectTransformParent, rectTransform);
                    }
                }
                break;
            }

            case EventType.MouseDrag:
            {
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePos += evt.delta;
                    if (!s_Moving && (s_CurrentMousePos - s_StartMousePos).magnitude > 3f)
                    {
                        s_Moving = true;
                        // Re-raycast to get start mouse pos when effective dragging starts.
                        // This prevents a sudden unsnap when the dragging is enabled.
                        RectHandles.RaycastGUIPointToWorldHit(s_CurrentMousePos, guiPlane, out s_StartMouseWorldPos);
                    }
                    if (s_Moving)
                    {
                        if (Tools.vertexDragging)
                        {
                            if (HandleUtility.ignoreRaySnapObjects == null)
                            {
                                Handles.SetupIgnoreRaySnapObjects();
                            }
                            Vector3 near;
                            if (HandleUtility.FindNearestVertex(s_CurrentMousePos, null, out near))
                            {
                                // Snap position based on found near vertex
                                newPos      = near;
                                GUI.changed = true;
                            }
                            ManipulationToolUtility.minDragDifference = Vector2.zero;
                        }
                        else
                        {
                            ManipulationToolUtility.SetMinDragDifferenceForPos(pivot);
                            Vector3 pos;
                            if (RectHandles.RaycastGUIPointToWorldHit(s_CurrentMousePos, guiPlane, out pos))
                            {
                                Vector3 offset = pos - s_StartMouseWorldPos;

                                // Snap to axis
                                if (evt.shift)
                                {
                                    // Get offset in rect handles space
                                    offset = Quaternion.Inverse(rotation) * offset;
                                    // Determine lock axis if not already set
                                    if (s_LockAxis == -1)
                                    {
                                        s_LockAxis = Mathf.Abs(offset.x) > Mathf.Abs(offset.y) ? 0 : 1;
                                    }
                                    // Cancel mocement on other axis
                                    offset[1 - s_LockAxis] = 0;
                                    // Put offset back in world space
                                    offset = rotation * offset;
                                }
                                else
                                {
                                    s_LockAxis = -1;
                                }

                                if (supportsRectSnapping)
                                {
                                    Transform transformParent = Selection.activeTransform.parent;
                                    Vector3   rectPosition    = s_StartRectPosition + transformParent.InverseTransformVector(offset);
                                    rectPosition.z = 0;

                                    Quaternion inverseRotation = Quaternion.Inverse(rotation);
                                    Vector2    snapSize        = Vector2.one * HandleUtility.GetHandleSize(newPos) * RectTransformSnapping.kSnapThreshold;
                                    snapSize.x /= (inverseRotation * transformParent.TransformVector(Vector3.right)).x;
                                    snapSize.y /= (inverseRotation * transformParent.TransformVector(Vector3.up)).y;

                                    Vector3 newRectPosition = RectTransformSnapping.SnapToGuides(rectPosition, snapSize);
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(rectPosition, newRectPosition);
                                    offset = transformParent.TransformVector(newRectPosition - s_StartRectPosition);
                                }

                                newPos = s_StartPosition + offset;

                                GUI.changed = true;
                            }
                        }
                    }
                    evt.Use();
                }
                break;
            }

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

            case EventType.Repaint:
            {
                if (Tools.vertexDragging)
                {
                    RectHandles.RectScalingHandleCap(id, pivot, rotation, 1, EventType.Repaint);
                }
                else
                {
                    Handles.color = Handles.secondaryColor * new Color(1, 1, 1, 1.5f * discOpacity);
                    Handles.CircleHandleCap(id, pivot, rotation, discSize, EventType.Repaint);
                    Handles.color = Handles.secondaryColor * new Color(1, 1, 1, 0.3f * discOpacity);
                    Handles.DrawSolidDisc(pivot, rotation * Vector3.forward, discSize);
                }
                break;
            }
            }

            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingPosX, eventType);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingLeft, eventType);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingRight, eventType);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingPosY, eventType);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingTop, eventType);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingBottom, eventType);

            return(newPos);
        }
        public void OnGUI()
        {
            Event current = Event.current;

            Handles.BeginGUI();
            Vector2   mousePosition  = current.mousePosition;
            int       controlID      = s_RectSelectionID;
            EventType typeForControl = current.GetTypeForControl(controlID);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if ((HandleUtility.nearestControl == controlID) && (current.button == 0))
                {
                    GUIUtility.hotControl   = controlID;
                    this.m_SelectStartPoint = mousePosition;
                    this.m_SelectionStart   = Selection.objects;
                    this.m_RectSelecting    = false;
                }
                goto Label_04F7;

            case EventType.MouseUp:
                if ((GUIUtility.hotControl == controlID) && (current.button == 0))
                {
                    GUIUtility.hotControl = 0;
                    if (!this.m_RectSelecting)
                    {
                        if (current.shift || EditorGUI.actionKey)
                        {
                            GameObject obj5 = HandleUtility.PickGameObject(current.mousePosition, false);
                            if (!EditorGUI.actionKey ? (Selection.activeGameObject == obj5) : Selection.gameObjects.Contains <GameObject>(obj5))
                            {
                                UpdateSelection(this.m_SelectionStart, obj5, SelectionType.Subtractive, this.m_RectSelecting);
                            }
                            else
                            {
                                UpdateSelection(this.m_SelectionStart, HandleUtility.PickGameObject(current.mousePosition, true), SelectionType.Additive, this.m_RectSelecting);
                            }
                        }
                        else
                        {
                            GameObject newObject = SceneViewPicking.PickGameObject(current.mousePosition);
                            UpdateSelection(this.m_SelectionStart, newObject, SelectionType.Normal, this.m_RectSelecting);
                        }
                        current.Use();
                    }
                    else
                    {
                        EditorApplication.modifierKeysChanged = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.modifierKeysChanged, new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys));
                        this.m_RectSelecting  = false;
                        this.m_SelectionStart = new UnityEngine.Object[0];
                        current.Use();
                    }
                }
                goto Label_04F7;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl != controlID)
                {
                    goto Label_04F7;
                }
                if (!this.m_RectSelecting)
                {
                    Vector2 vector2 = mousePosition - this.m_SelectStartPoint;
                    if (vector2.magnitude > 6f)
                    {
                        EditorApplication.modifierKeysChanged = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.modifierKeysChanged, new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys));
                        this.m_RectSelecting    = true;
                        this.m_LastSelection    = null;
                        this.m_CurrentSelection = null;
                    }
                }
                if (this.m_RectSelecting)
                {
                    float x = Mathf.Max(mousePosition.x, 0f);
                    this.m_SelectMousePoint = new Vector2(x, Mathf.Max(mousePosition.y, 0f));
                    GameObject[] newObjects = HandleUtility.PickRectObjects(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint));
                    this.m_CurrentSelection = newObjects;
                    bool flag = false;
                    if (this.m_LastSelection == null)
                    {
                        this.m_LastSelection = new Dictionary <GameObject, bool>();
                        flag = true;
                    }
                    flag |= this.m_LastSelection.Count != newObjects.Length;
                    if (!flag)
                    {
                        Dictionary <GameObject, bool> dictionary = new Dictionary <GameObject, bool>(newObjects.Length);
                        foreach (GameObject obj2 in newObjects)
                        {
                            dictionary.Add(obj2, false);
                        }
                        foreach (GameObject obj3 in this.m_LastSelection.Keys)
                        {
                            if (!dictionary.ContainsKey(obj3))
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (flag)
                    {
                        this.m_LastSelection = new Dictionary <GameObject, bool>(newObjects.Length);
                        foreach (GameObject obj4 in newObjects)
                        {
                            this.m_LastSelection.Add(obj4, false);
                        }
                        if (newObjects != null)
                        {
                            if (current.shift)
                            {
                                UpdateSelection(this.m_SelectionStart, newObjects, SelectionType.Additive, this.m_RectSelecting);
                            }
                            else if (EditorGUI.actionKey)
                            {
                                UpdateSelection(this.m_SelectionStart, newObjects, SelectionType.Subtractive, this.m_RectSelecting);
                            }
                            else
                            {
                                UpdateSelection(this.m_SelectionStart, newObjects, SelectionType.Normal, this.m_RectSelecting);
                            }
                        }
                    }
                }
                break;

            case EventType.Repaint:
                if ((GUIUtility.hotControl == controlID) && this.m_RectSelecting)
                {
                    EditorStyles.selectionRect.Draw(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint), GUIContent.none, false, false, false, false);
                }
                goto Label_04F7;

            case EventType.Layout:
                if (!Tools.viewToolActive)
                {
                    HandleUtility.AddDefaultControl(controlID);
                }
                goto Label_04F7;

            default:
                if ((typeForControl == EventType.ExecuteCommand) && ((controlID == GUIUtility.hotControl) && (current.commandName == "ModifierKeysChanged")))
                {
                    if (current.shift)
                    {
                        UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, SelectionType.Additive, this.m_RectSelecting);
                    }
                    else if (EditorGUI.actionKey)
                    {
                        UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, SelectionType.Subtractive, this.m_RectSelecting);
                    }
                    else
                    {
                        UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, SelectionType.Normal, this.m_RectSelecting);
                    }
                    current.Use();
                }
                goto Label_04F7;
            }
            current.Use();
Label_04F7:
            Handles.EndGUI();
        }
        public void OnGUI()
        {
            Event evt = Event.current;

            Handles.BeginGUI();

            Vector2 mousePos = evt.mousePosition;
            int     id       = s_RectSelectionID;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
            case EventType.MouseMove:
                if (!Tools.viewToolActive)
                {
                    HandleUtility.AddDefaultControl(id);
                }
                break;

            case EventType.MouseDown:
                if (HandleUtility.nearestControl == id && evt.button == 0)
                {
                    GUIUtility.hotControl = id;
                    m_SelectStartPoint    = mousePos;
                    m_SelectionStart      = Selection.objects;
                    m_RectSelecting       = false;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    if (!m_RectSelecting && (mousePos - m_SelectStartPoint).magnitude > 6f)
                    {
                        EditorApplication.modifierKeysChanged += SendCommandsOnModifierKeys;
                        m_RectSelecting = true;
                        ActiveEditorTracker.delayFlushDirtyRebuild = true;
                        m_LastSelection    = null;
                        m_CurrentSelection = null;
                        rectSelectionStarting();
                    }
                    if (m_RectSelecting)
                    {
                        m_SelectMousePoint = new Vector2(Mathf.Max(mousePos.x, 0), Mathf.Max(mousePos.y, 0));
                        GameObject[] rectObjs = HandleUtility.PickRectObjects(EditorGUIExt.FromToRect(m_SelectStartPoint, m_SelectMousePoint));
                        m_CurrentSelection = rectObjs;
                        bool setIt = false;
                        if (m_LastSelection == null)
                        {
                            m_LastSelection = new Dictionary <GameObject, bool>();
                            setIt           = true;
                        }
                        setIt |= m_LastSelection.Count != rectObjs.Length;
                        if (!setIt)
                        {
                            Dictionary <GameObject, bool> set = new Dictionary <GameObject, bool>(rectObjs.Length);
                            foreach (GameObject g in rectObjs)
                            {
                                set.Add(g, false);
                            }
                            foreach (GameObject g in m_LastSelection.Keys)
                            {
                                if (!set.ContainsKey(g))
                                {
                                    setIt = true;
                                    break;
                                }
                            }
                        }
                        if (setIt)
                        {
                            m_LastSelection = new Dictionary <GameObject, bool>(rectObjs.Length);
                            foreach (GameObject g in rectObjs)
                            {
                                m_LastSelection.Add(g, false);
                            }
                            if (evt.shift)
                            {
                                UpdateSelection(m_SelectionStart, rectObjs, SelectionType.Additive, m_RectSelecting);
                            }
                            else if (EditorGUI.actionKey)
                            {
                                UpdateSelection(m_SelectionStart, rectObjs, SelectionType.Subtractive, m_RectSelecting);
                            }
                            else
                            {
                                UpdateSelection(m_SelectionStart, rectObjs, SelectionType.Normal, m_RectSelecting);
                            }
                        }
                    }
                    evt.Use();
                }
                break;

            case EventType.Repaint:
                if (GUIUtility.hotControl == id && m_RectSelecting)
                {
                    EditorStyles.selectionRect.Draw(EditorGUIExt.FromToRect(m_SelectStartPoint, m_SelectMousePoint), GUIContent.none, false, false, false, false);
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && evt.button == 0)
                {
                    GUIUtility.hotControl = 0;
                    if (m_RectSelecting)
                    {
                        EditorApplication.modifierKeysChanged -= SendCommandsOnModifierKeys;
                        m_RectSelecting = false;
                        ActiveEditorTracker.delayFlushDirtyRebuild = false;
                        ActiveEditorTracker.RebuildAllIfNecessary();
                        m_SelectionStart = new Object[0];
                        rectSelectionFinished();
                        evt.Use();
                    }
                    else
                    {
                        if (evt.shift || EditorGUI.actionKey)
                        {
                            // For shift, we check if EXACTLY the active GO is hovered by mouse and then subtract. Otherwise additive.
                            // For control/cmd, we check if ANY of the selected GO is hovered by mouse and then subtract. Otherwise additive.
                            // Control/cmd takes priority over shift.
                            GameObject hovered = HandleUtility.PickGameObject(evt.mousePosition, false);
                            if (EditorGUI.actionKey ? Selection.gameObjects.Contains(hovered) : Selection.activeGameObject == hovered)
                            {
                                UpdateSelection(m_SelectionStart, hovered, SelectionType.Subtractive, m_RectSelecting);
                            }
                            else
                            {
                                UpdateSelection(m_SelectionStart, HandleUtility.PickGameObject(evt.mousePosition, true), SelectionType.Additive, m_RectSelecting);
                            }
                        }
                        else     // With no modifier keys, we do the "cycle through overlapped" picking logic in SceneViewPicking.cs
                        {
                            GameObject picked = SceneViewPicking.PickGameObject(evt.mousePosition);
                            UpdateSelection(m_SelectionStart, picked, SelectionType.Normal, m_RectSelecting);
                        }

                        evt.Use();
                    }
                }
                break;

            case EventType.ExecuteCommand:
                if (id == GUIUtility.hotControl && evt.commandName == EventCommandNames.ModifierKeysChanged)
                {
                    if (evt.shift)
                    {
                        UpdateSelection(m_SelectionStart, m_CurrentSelection, SelectionType.Additive, m_RectSelecting);
                    }
                    else if (EditorGUI.actionKey)
                    {
                        UpdateSelection(m_SelectionStart, m_CurrentSelection, SelectionType.Subtractive, m_RectSelecting);
                    }
                    else
                    {
                        UpdateSelection(m_SelectionStart, m_CurrentSelection, SelectionType.Normal, m_RectSelecting);
                    }
                    evt.Use();
                }
                break;
            }

            Handles.EndGUI();
        }
Exemple #4
0
        public void OnGUI()
        {
            Event evt = Event.current;

            Handles.BeginGUI();

            Vector2 mousePos = evt.mousePosition;
            int     id       = s_RectSelectionID;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
            case EventType.MouseMove:
                if (!Tools.viewToolActive)
                {
                    HandleUtility.AddDefaultControl(id);
                }

                //Handle the case of the drag being canceled
                if (m_RectSelecting && GUIUtility.hotControl != id)
                {
                    CompleteRectSelection();
                }
                break;

            case EventType.MouseDown:
                if (HandleUtility.nearestControl == id && evt.button == 0)
                {
                    GUIUtility.hotControl = id;
                    m_SelectStartPoint    = mousePos;
                    m_SelectionStart      = Selection.objects;
                    m_RectSelecting       = false;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    if (!m_RectSelecting && (mousePos - m_SelectStartPoint).magnitude > 6f)
                    {
                        EditorApplication.modifierKeysChanged += SendCommandsOnModifierKeys;
                        m_RectSelecting = true;
                        ActiveEditorTracker.delayFlushDirtyRebuild = true;
                        m_LastSelection    = null;
                        m_CurrentSelection = null;
                        rectSelectionStarting();
                    }
                    if (m_RectSelecting)
                    {
                        m_SelectMousePoint = new Vector2(Mathf.Max(mousePos.x, 0), Mathf.Max(mousePos.y, 0));
                        GameObject[] rectObjs = HandleUtility.PickRectObjects(EditorGUIExt.FromToRect(m_SelectStartPoint, m_SelectMousePoint));
                        m_CurrentSelection = rectObjs;
                        bool setIt = false;
                        if (m_LastSelection == null)
                        {
                            m_LastSelection = new Dictionary <GameObject, bool>();
                            setIt           = true;
                        }
                        setIt |= m_LastSelection.Count != rectObjs.Length;
                        if (!setIt)
                        {
                            Dictionary <GameObject, bool> set = new Dictionary <GameObject, bool>(rectObjs.Length);
                            foreach (GameObject g in rectObjs)
                            {
                                set.Add(g, false);
                            }
                            foreach (GameObject g in m_LastSelection.Keys)
                            {
                                if (!set.ContainsKey(g))
                                {
                                    setIt = true;
                                    break;
                                }
                            }
                        }
                        if (setIt)
                        {
                            m_LastSelection = new Dictionary <GameObject, bool>(rectObjs.Length);
                            foreach (GameObject g in rectObjs)
                            {
                                m_LastSelection.Add(g, false);
                            }
                            if (evt.shift)
                            {
                                UpdateSelection(m_SelectionStart, rectObjs, SelectionType.Additive, m_RectSelecting);
                            }
                            else if (EditorGUI.actionKey)
                            {
                                UpdateSelection(m_SelectionStart, rectObjs, SelectionType.Subtractive, m_RectSelecting);
                            }
                            else
                            {
                                UpdateSelection(m_SelectionStart, rectObjs, SelectionType.Normal, m_RectSelecting);
                            }
                        }
                    }
                    evt.Use();
                }
                break;

            case EventType.Repaint:
                if (GUIUtility.hotControl == id && m_RectSelecting)
                {
                    EditorStyles.selectionRect.Draw(EditorGUIExt.FromToRect(m_SelectStartPoint, m_SelectMousePoint), GUIContent.none, false, false, false, false);
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && evt.button == 0)
                {
                    GUIUtility.hotControl = 0;
                    if (m_RectSelecting)
                    {
                        CompleteRectSelection();
                        evt.Use();
                    }
                    else
                    {
                        if (evt.shift || EditorGUI.actionKey)
                        {
                            // For shift, we check if EXACTLY the active GO is hovered by mouse and then subtract. Otherwise additive.
                            // For control/cmd, we check if ANY of the selected GO is hovered by mouse and then subtract. Otherwise additive.
                            // Control/cmd takes priority over shift.
                            GameObject hovered = HandleUtility.PickGameObject(evt.mousePosition, false);

                            var handledIt = false;
                            // shift-click deselects only if the active GO is exactly what we clicked on
                            if (!EditorGUI.actionKey && Selection.activeGameObject == hovered)
                            {
                                UpdateSelection(m_SelectionStart, hovered, SelectionType.Subtractive, m_RectSelecting);
                                handledIt = true;
                            }

                            // ctrl-click deselects everything up to prefab root, that is already selected
                            if (!handledIt && EditorGUI.actionKey)
                            {
                                var selectedGos  = Selection.gameObjects;
                                var hoveredRoot  = HandleUtility.FindSelectionBaseForPicking(hovered);
                                var deselectList = new List <Object>();
                                while (hovered != null)
                                {
                                    if (selectedGos.Contains(hovered))
                                    {
                                        deselectList.Add(hovered);
                                    }
                                    if (hovered == hoveredRoot)
                                    {
                                        break;
                                    }
                                    var parent = hovered.transform.parent;
                                    if (parent)
                                    {
                                        hovered = parent.gameObject;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                if (deselectList.Any())
                                {
                                    UpdateSelection(m_SelectionStart, deselectList.ToArray(), SelectionType.Subtractive, m_RectSelecting);
                                    handledIt = true;
                                }
                            }

                            // we did not deselect anything, so add the new thing into selection instead
                            if (!handledIt)
                            {
                                UpdateSelection(m_SelectionStart, HandleUtility.PickGameObject(evt.mousePosition, true), SelectionType.Additive, m_RectSelecting);
                            }
                        }
                        else     // With no modifier keys, we do the "cycle through overlapped" picking logic in SceneViewPicking.cs
                        {
                            GameObject picked = SceneViewPicking.PickGameObject(evt.mousePosition);
                            UpdateSelection(m_SelectionStart, picked, SelectionType.Normal, m_RectSelecting);
                        }

                        evt.Use();
                    }
                }
                break;

            case EventType.ExecuteCommand:
                if (id == GUIUtility.hotControl && evt.commandName == EventCommandNames.ModifierKeysChanged)
                {
                    if (evt.shift)
                    {
                        UpdateSelection(m_SelectionStart, m_CurrentSelection, SelectionType.Additive, m_RectSelecting);
                    }
                    else if (EditorGUI.actionKey)
                    {
                        UpdateSelection(m_SelectionStart, m_CurrentSelection, SelectionType.Subtractive, m_RectSelecting);
                    }
                    else
                    {
                        UpdateSelection(m_SelectionStart, m_CurrentSelection, SelectionType.Normal, m_RectSelecting);
                    }
                    evt.Use();
                }
                break;
            }

            Handles.EndGUI();
        }
        public void OnGUI()
        {
            Event current = Event.current;

            Handles.BeginGUI();
            Vector2   mousePosition  = current.mousePosition;
            int       num            = RectSelection.s_RectSelectionID;
            EventType typeForControl = current.GetTypeForControl(num);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (HandleUtility.nearestControl == num && current.button == 0)
                {
                    GUIUtility.hotControl   = num;
                    this.m_SelectStartPoint = mousePosition;
                    this.m_SelectionStart   = Selection.objects;
                    this.m_RectSelecting    = false;
                }
                goto IL_4F7;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == num && current.button == 0)
                {
                    GUIUtility.hotControl = 0;
                    if (this.m_RectSelecting)
                    {
                        EditorApplication.modifierKeysChanged = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.modifierKeysChanged, new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys));
                        this.m_RectSelecting  = false;
                        this.m_SelectionStart = new UnityEngine.Object[0];
                        current.Use();
                    }
                    else
                    {
                        if (current.shift || EditorGUI.actionKey)
                        {
                            GameObject gameObject = HandleUtility.PickGameObject(current.mousePosition, false);
                            if ((!EditorGUI.actionKey) ? (Selection.activeGameObject == gameObject) : Selection.gameObjects.Contains(gameObject))
                            {
                                RectSelection.UpdateSelection(this.m_SelectionStart, gameObject, RectSelection.SelectionType.Subtractive, this.m_RectSelecting);
                            }
                            else
                            {
                                RectSelection.UpdateSelection(this.m_SelectionStart, HandleUtility.PickGameObject(current.mousePosition, true), RectSelection.SelectionType.Additive, this.m_RectSelecting);
                            }
                        }
                        else
                        {
                            GameObject newObject = SceneViewPicking.PickGameObject(current.mousePosition);
                            RectSelection.UpdateSelection(this.m_SelectionStart, newObject, RectSelection.SelectionType.Normal, this.m_RectSelecting);
                        }
                        current.Use();
                    }
                }
                goto IL_4F7;

            case EventType.MouseMove:
            case EventType.KeyDown:
            case EventType.KeyUp:
            case EventType.ScrollWheel:
IL_4B:
                if (typeForControl != EventType.ExecuteCommand)
                {
                    goto IL_4F7;
                }
                if (num == GUIUtility.hotControl && current.commandName == "ModifierKeysChanged")
                {
                    if (current.shift)
                    {
                        RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Additive, this.m_RectSelecting);
                    }
                    else if (EditorGUI.actionKey)
                    {
                        RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Subtractive, this.m_RectSelecting);
                    }
                    else
                    {
                        RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Normal, this.m_RectSelecting);
                    }
                    current.Use();
                }
                goto IL_4F7;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == num)
                {
                    if (!this.m_RectSelecting && (mousePosition - this.m_SelectStartPoint).magnitude > 6f)
                    {
                        EditorApplication.modifierKeysChanged = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.modifierKeysChanged, new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys));
                        this.m_RectSelecting    = true;
                        this.m_LastSelection    = null;
                        this.m_CurrentSelection = null;
                    }
                    if (this.m_RectSelecting)
                    {
                        this.m_SelectMousePoint = new Vector2(Mathf.Max(mousePosition.x, 0f), Mathf.Max(mousePosition.y, 0f));
                        GameObject[] array = HandleUtility.PickRectObjects(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint));
                        this.m_CurrentSelection = array;
                        bool flag = false;
                        if (this.m_LastSelection == null)
                        {
                            this.m_LastSelection = new Dictionary <GameObject, bool>();
                            flag = true;
                        }
                        flag |= (this.m_LastSelection.Count != array.Length);
                        if (!flag)
                        {
                            Dictionary <GameObject, bool> dictionary = new Dictionary <GameObject, bool>(array.Length);
                            GameObject[] array2 = array;
                            for (int i = 0; i < array2.Length; i++)
                            {
                                GameObject key = array2[i];
                                dictionary.Add(key, false);
                            }
                            foreach (GameObject current2 in this.m_LastSelection.Keys)
                            {
                                if (!dictionary.ContainsKey(current2))
                                {
                                    flag = true;
                                    break;
                                }
                            }
                        }
                        if (flag)
                        {
                            this.m_LastSelection = new Dictionary <GameObject, bool>(array.Length);
                            GameObject[] array3 = array;
                            for (int j = 0; j < array3.Length; j++)
                            {
                                GameObject key2 = array3[j];
                                this.m_LastSelection.Add(key2, false);
                            }
                            if (array != null)
                            {
                                if (current.shift)
                                {
                                    RectSelection.UpdateSelection(this.m_SelectionStart, array, RectSelection.SelectionType.Additive, this.m_RectSelecting);
                                }
                                else if (EditorGUI.actionKey)
                                {
                                    RectSelection.UpdateSelection(this.m_SelectionStart, array, RectSelection.SelectionType.Subtractive, this.m_RectSelecting);
                                }
                                else
                                {
                                    RectSelection.UpdateSelection(this.m_SelectionStart, array, RectSelection.SelectionType.Normal, this.m_RectSelecting);
                                }
                            }
                        }
                    }
                    current.Use();
                }
                goto IL_4F7;

            case EventType.Repaint:
                if (GUIUtility.hotControl == num && this.m_RectSelecting)
                {
                    EditorStyles.selectionRect.Draw(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint), GUIContent.none, false, false, false, false);
                }
                goto IL_4F7;

            case EventType.Layout:
                if (!Tools.viewToolActive)
                {
                    HandleUtility.AddDefaultControl(num);
                }
                goto IL_4F7;
            }
            goto IL_4B;
IL_4F7:
            Handles.EndGUI();
        }
Exemple #6
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);
        }
Exemple #7
0
        private static Vector3 MoveHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            bool    flag2;
            int     controlID = GUIUtility.GetControlID(s_MoveHandleHash, FocusType.Passive);
            Vector3 position  = pivot;
            float   radius    = HandleUtility.GetHandleSize(pivot) * 0.2f;
            float   num3      = 1f - GUI.color.a;

            Vector3[] worldPoints = 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(worldPoints[0], worldPoints[1], worldPoints[2]);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                flag2 = false;
                if (!Tools.vertexDragging)
                {
                    flag2 = (((current.button == 0) && (current.modifiers == EventModifiers.None)) && RectHandles.RaycastGUIPointToWorldHit(current.mousePosition, plane, out s_StartMouseWorldPos)) && ((SceneViewDistanceToRectangle(worldPoints, current.mousePosition) == 0f) || ((num3 > 0f) && (SceneViewDistanceToDisc(pivot, (Vector3)(rotation * Vector3.forward), radius, current.mousePosition) == 0f)));
                    break;
                }
                flag2 = true;
                break;

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

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    s_CurrentMousePos += current.delta;
                    if (!s_Moving)
                    {
                        Vector2 vector2 = s_CurrentMousePos - s_StartMousePos;
                        if (vector2.magnitude > 3f)
                        {
                            s_Moving = true;
                            RectHandles.RaycastGUIPointToWorldHit(s_CurrentMousePos, plane, out s_StartMouseWorldPos);
                        }
                    }
                    if (s_Moving)
                    {
                        if (!Tools.vertexDragging)
                        {
                            Vector3 vector4;
                            ManipulationToolUtility.SetMinDragDifferenceForPos(pivot);
                            if (RectHandles.RaycastGUIPointToWorldHit(s_CurrentMousePos, plane, out vector4))
                            {
                                Vector3 vector = vector4 - s_StartMouseWorldPos;
                                if (current.shift)
                                {
                                    vector = (Vector3)(Quaternion.Inverse(rotation) * vector);
                                    if (s_LockAxis == -1)
                                    {
                                        float introduced28 = Mathf.Abs(vector.x);
                                        s_LockAxis = (introduced28 <= Mathf.Abs(vector.y)) ? 1 : 0;
                                    }
                                    vector[1 - s_LockAxis] = 0f;
                                    vector = (Vector3)(rotation * vector);
                                }
                                else
                                {
                                    s_LockAxis = -1;
                                }
                                if (flag)
                                {
                                    Transform parent  = Selection.activeTransform.parent;
                                    Vector3   vector6 = s_StartRectPosition + parent.InverseTransformVector(vector);
                                    vector6.z = 0f;
                                    Quaternion quaternion   = Quaternion.Inverse(rotation);
                                    Vector2    snapDistance = (Vector2)((Vector2.one * HandleUtility.GetHandleSize(position)) * 0.05f);
                                    Vector3    vector8      = (Vector3)(quaternion * parent.TransformVector(Vector3.right));
                                    snapDistance.x /= vector8.x;
                                    Vector3 vector9 = (Vector3)(quaternion * parent.TransformVector(Vector3.up));
                                    snapDistance.y /= vector9.y;
                                    Vector3 positionAfterSnapping = (Vector3)RectTransformSnapping.SnapToGuides(vector6, snapDistance);
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(vector6, positionAfterSnapping);
                                    vector = parent.TransformVector(positionAfterSnapping - s_StartRectPosition);
                                }
                                position    = s_StartPosition + vector;
                                GUI.changed = true;
                            }
                        }
                        else
                        {
                            Vector3 vector3;
                            if (HandleUtility.ignoreRaySnapObjects == null)
                            {
                                Handles.SetupIgnoreRaySnapObjects();
                            }
                            if (HandleUtility.FindNearestVertex(s_CurrentMousePos, null, out vector3))
                            {
                                position    = vector3;
                                GUI.changed = true;
                            }
                            ManipulationToolUtility.minDragDifference = (Vector3)Vector2.zero;
                        }
                    }
                    current.Use();
                }
                goto Label_0620;

            case EventType.Repaint:
                if (!Tools.vertexDragging)
                {
                    Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 1.5f * num3);
                    Handles.CircleCap(controlID, pivot, rotation, radius);
                    Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 0.3f * num3);
                    Handles.DrawSolidDisc(pivot, (Vector3)(rotation * Vector3.forward), radius);
                }
                else
                {
                    RectHandles.RectScalingHandleCap(controlID, pivot, rotation, 1f, EventType.Repaint);
                }
                goto Label_0620;

            default:
                goto Label_0620;
            }
            if (flag2)
            {
                s_StartPosition = pivot;
                s_StartMousePos = s_CurrentMousePos = current.mousePosition;
                s_Moving        = false;
                s_LockAxis      = -1;
                int num4 = controlID;
                GUIUtility.keyboardControl = num4;
                GUIUtility.hotControl      = num4;
                EditorGUIUtility.SetWantsMouseJumping(1);
                HandleUtility.ignoreRaySnapObjects = null;
                current.Use();
                if (flag)
                {
                    Transform     activeTransform = Selection.activeTransform;
                    RectTransform component       = activeTransform.GetComponent <RectTransform>();
                    Transform     parentSpace     = activeTransform.parent;
                    RectTransform parentRect      = parentSpace.GetComponent <RectTransform>();
                    s_StartRectPosition = (Vector3)component.anchoredPosition;
                    RectTransformSnapping.CalculatePositionSnapValues(parentSpace, activeTransform, parentRect, component);
                }
            }
Label_0620:
            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);
        }
Exemple #8
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);
        }
        public void OnGUI()
        {
            Event current1 = Event.current;

            Handles.BeginGUI();
            Vector2   mousePosition   = current1.mousePosition;
            int       rectSelectionId = RectSelection.s_RectSelectionID;
            EventType typeForControl  = current1.GetTypeForControl(rectSelectionId);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (HandleUtility.nearestControl == rectSelectionId && current1.button == 0)
                {
                    GUIUtility.hotControl   = rectSelectionId;
                    this.m_SelectStartPoint = mousePosition;
                    this.m_SelectionStart   = Selection.objects;
                    this.m_RectSelecting    = false;
                    break;
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == rectSelectionId && current1.button == 0)
                {
                    GUIUtility.hotControl = 0;
                    if (this.m_RectSelecting)
                    {
                        EditorApplication.modifierKeysChanged -= new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys);
                        this.m_RectSelecting  = false;
                        this.m_SelectionStart = new UnityEngine.Object[0];
                        current1.Use();
                        break;
                    }
                    if (current1.shift || EditorGUI.actionKey)
                    {
                        GameObject[] gameObjectArray;
                        if (current1.shift)
                        {
                            gameObjectArray = new GameObject[1]
                            {
                                Selection.activeGameObject
                            }
                        }
                        ;
                        else
                        {
                            gameObjectArray = Selection.gameObjects;
                        }
                        GameObject[] gameObjects = gameObjectArray;
                        GameObject   hovered     = SceneViewPicking.GetHovered(current1.mousePosition, gameObjects);
                        if ((UnityEngine.Object)hovered != (UnityEngine.Object)null)
                        {
                            RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object)hovered, RectSelection.SelectionType.Subtractive, this.m_RectSelecting);
                        }
                        else
                        {
                            RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object)HandleUtility.PickGameObject(current1.mousePosition, true), RectSelection.SelectionType.Additive, this.m_RectSelecting);
                        }
                    }
                    else
                    {
                        RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object)SceneViewPicking.PickGameObject(current1.mousePosition), RectSelection.SelectionType.Normal, this.m_RectSelecting);
                    }
                    current1.Use();
                    break;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == rectSelectionId)
                {
                    if (!this.m_RectSelecting && (double)(mousePosition - this.m_SelectStartPoint).magnitude > 6.0)
                    {
                        EditorApplication.modifierKeysChanged += new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys);
                        this.m_RectSelecting    = true;
                        this.m_LastSelection    = (Dictionary <GameObject, bool>)null;
                        this.m_CurrentSelection = (UnityEngine.Object[])null;
                    }
                    if (this.m_RectSelecting)
                    {
                        this.m_SelectMousePoint = new Vector2(Mathf.Max(mousePosition.x, 0.0f), Mathf.Max(mousePosition.y, 0.0f));
                        GameObject[] gameObjectArray = HandleUtility.PickRectObjects(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint));
                        this.m_CurrentSelection = (UnityEngine.Object[])gameObjectArray;
                        bool flag1 = false;
                        if (this.m_LastSelection == null)
                        {
                            this.m_LastSelection = new Dictionary <GameObject, bool>();
                            flag1 = true;
                        }
                        bool flag2 = flag1 | this.m_LastSelection.Count != gameObjectArray.Length;
                        if (!flag2)
                        {
                            Dictionary <GameObject, bool> dictionary = new Dictionary <GameObject, bool>(gameObjectArray.Length);
                            foreach (GameObject key in gameObjectArray)
                            {
                                dictionary.Add(key, false);
                            }
                            using (Dictionary <GameObject, bool> .KeyCollection.Enumerator enumerator = this.m_LastSelection.Keys.GetEnumerator())
                            {
                                while (enumerator.MoveNext())
                                {
                                    GameObject current2 = enumerator.Current;
                                    if (!dictionary.ContainsKey(current2))
                                    {
                                        flag2 = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (flag2)
                        {
                            this.m_LastSelection = new Dictionary <GameObject, bool>(gameObjectArray.Length);
                            foreach (GameObject key in gameObjectArray)
                            {
                                this.m_LastSelection.Add(key, false);
                            }
                            if (gameObjectArray != null)
                            {
                                if (current1.shift)
                                {
                                    RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object[])gameObjectArray, RectSelection.SelectionType.Additive, this.m_RectSelecting);
                                }
                                else if (EditorGUI.actionKey)
                                {
                                    RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object[])gameObjectArray, RectSelection.SelectionType.Subtractive, this.m_RectSelecting);
                                }
                                else
                                {
                                    RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object[])gameObjectArray, RectSelection.SelectionType.Normal, this.m_RectSelecting);
                                }
                            }
                        }
                    }
                    current1.Use();
                    break;
                }
                break;

            case EventType.Repaint:
                if (GUIUtility.hotControl == rectSelectionId && this.m_RectSelecting)
                {
                    EditorStyles.selectionRect.Draw(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint), GUIContent.none, false, false, false, false);
                    break;
                }
                break;

            case EventType.Layout:
                if (!Tools.viewToolActive)
                {
                    HandleUtility.AddDefaultControl(rectSelectionId);
                    break;
                }
                break;

            default:
                if (typeForControl == EventType.ExecuteCommand && rectSelectionId == GUIUtility.hotControl && current1.commandName == "ModifierKeysChanged")
                {
                    if (current1.shift)
                    {
                        RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Additive, this.m_RectSelecting);
                    }
                    else if (EditorGUI.actionKey)
                    {
                        RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Subtractive, this.m_RectSelecting);
                    }
                    else
                    {
                        RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Normal, this.m_RectSelecting);
                    }
                    current1.Use();
                    break;
                }
                break;
            }
            Handles.EndGUI();
        }