AddDefaultControl() public static method

Add the ID for a default control. This will be picked if nothing else is.

public static AddDefaultControl ( int controlId ) : void
controlId int
return void
示例#1
0
        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();
        }