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();
        }
Beispiel #2
0
        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_04D2;

            case EventType.MouseUp:
                if ((GUIUtility.hotControl == controlID) && (current.button == 0))
                {
                    GUIUtility.hotControl = 0;
                    if (!this.m_RectSelecting)
                    {
                        if (current.shift || EditorGUI.actionKey)
                        {
                            GameObject[] gameObjects = !current.shift ? Selection.gameObjects : new GameObject[] { Selection.activeGameObject };
                            GameObject   hovered     = SceneViewPicking.GetHovered(current.mousePosition, gameObjects);
                            if (hovered != null)
                            {
                                UpdateSelection(this.m_SelectionStart, hovered, 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 Object[0];
                        current.Use();
                    }
                }
                goto Label_04D2;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl != controlID)
                {
                    goto Label_04D2;
                }
                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_04D2;

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

            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_04D2;
            }
            current.Use();
Label_04D2:
            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_4D2;

            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[] arg_3BA_0;
                            if (current.shift)
                            {
                                (arg_3BA_0 = new GameObject[1])[0] = Selection.activeGameObject;
                            }
                            else
                            {
                                arg_3BA_0 = Selection.gameObjects;
                            }
                            GameObject[] gameObjects = arg_3BA_0;
                            GameObject   hovered     = SceneViewPicking.GetHovered(current.mousePosition, gameObjects);
                            if (hovered != null)
                            {
                                RectSelection.UpdateSelection(this.m_SelectionStart, hovered, 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_4D2;

            case EventType.MouseMove:
            case EventType.KeyDown:
            case EventType.KeyUp:
            case EventType.ScrollWheel:
IL_4C:
                if (typeForControl != EventType.ExecuteCommand)
                {
                    goto IL_4D2;
                }
                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_4D2;

            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_4D2;

            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_4D2;

            case EventType.Layout:
                if (!Tools.viewToolActive)
                {
                    HandleUtility.AddDefaultControl(num);
                }
                goto IL_4D2;
            }
            goto IL_4C;
IL_4D2:
            Handles.EndGUI();
        }