UnityEditor.RectSelection.OnGUI C# (CSharp) Method

OnGUI() public method

public OnGUI ( ) : void
return void
        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) : Enumerable.Contains<GameObject>(Selection.gameObjects, 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 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();
        }