Пример #1
0
        private void HandleKeyHandlerGUI(GUIContent name, Utils.KeyHandler keyHandler, GUISkin skin)
        {
            const int keyButtonWidth = 90;

            GUILayout.BeginHorizontal();
            {
                keyHandler.Enable = GUI.Toggle(name,
                                               keyHandler.Enable,
                                               skin.button,
                                               GUI.Align(skin.label, TextAnchor.MiddleLeft),
                                               new GUILayoutOption[] { GUILayout.Width(ToggleButtonSize), GUILayout.Height(ToggleButtonSize) },
                                               new GUILayoutOption[] { GUILayout.Height(ToggleButtonSize) });
                GUILayout.FlexibleSpace();

                UnityEngine.GUI.enabled = keyHandler.Enable;

                for (int iKey = 0; iKey < keyHandler.NumKeyCodes; ++iKey)
                {
                    GUIContent buttonLabel = keyHandler.IsDetectingKey(iKey) ?
                                             GUI.MakeLabel("Detecting...") :
                                             GUI.MakeLabel(keyHandler.Keys[iKey].ToString());

                    bool toggleDetecting = GUILayout.Button(buttonLabel, skin.button, GUILayout.Width(keyButtonWidth), GUILayout.Height(ToggleButtonSize));
                    if (toggleDetecting)
                    {
                        keyHandler.DetectKey(this, !keyHandler.IsDetectingKey(iKey), iKey);
                    }
                }

                Rect dropDownButtonRect = new Rect();
                GUILayout.BeginVertical(GUILayout.Height(ToggleButtonSize));
                {
                    GUIStyle tmp = new GUIStyle(skin.button);
                    tmp.fontSize = 6;

                    m_showDropDown = GUILayout.Button(GUI.MakeLabel("v", true), tmp, GUILayout.Width(16), GUILayout.Height(14)) ?
                                     !m_showDropDown :
                                     m_showDropDown;
                    dropDownButtonRect = GUILayoutUtility.GetLastRect();
                    GUILayout.FlexibleSpace();
                }
                GUILayout.EndVertical();

                UnityEngine.GUI.enabled = true;

                if (m_showDropDown && dropDownButtonRect.Contains(Event.current.mousePosition))
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(GUI.MakeLabel("Reset to default"), false, () =>
                    {
                        if (EditorUtility.DisplayDialog("Reset to default", "Reset key(s) to default?", "OK", "Cancel"))
                        {
                            keyHandler.ResetToDefault();
                        }
                    });
                    menu.AddItem(GUI.MakeLabel("Add key"), false, () =>
                    {
                        keyHandler.Add(KeyCode.None);
                    });

                    if (keyHandler.NumKeyCodes > 1)
                    {
                        menu.AddItem(GUI.MakeLabel("Remove key"), false, () =>
                        {
                            if (EditorUtility.DisplayDialog("Remove key", "Remove key: " + keyHandler[keyHandler.NumKeyCodes - 1].ToString() + "?", "OK", "Cancel"))
                            {
                                keyHandler.Remove(keyHandler.NumKeyCodes - 1);
                            }
                        });
                    }

                    menu.ShowAsContext();
                }
            }
            GUILayout.EndHorizontal();

            if (UnityEngine.GUI.changed)
            {
                EditorUtility.SetDirty(this);
            }
        }
Пример #2
0
        public static void TargetEditorEnable <T>(T target, GUISkin skin) where T : class
        {
            KeyHandler.HandleDetectKeyOnEnable(target);

            Tools.Tool.ActivateToolGivenTarget(target);
        }
Пример #3
0
 public static bool TargetEditorOnInspectorGUI <T>(T target, GUISkin skin) where T : class
 {
     return(KeyHandler.HandleDetectKeyOnGUI(target, Event.current));
 }
Пример #4
0
        private void HandleKeyHandlerGUI(GUIContent name, Utils.KeyHandler keyHandler)
        {
            const int keyButtonWidth      = 90;
            var       showDropdownPressed = false;

            GUILayout.BeginHorizontal();
            {
                keyHandler.Enable = InspectorGUI.Toggle(name, keyHandler.Enable);
                GUILayout.FlexibleSpace();

                UnityEngine.GUI.enabled = keyHandler.Enable;

                for (int iKey = 0; iKey < keyHandler.NumKeyCodes; ++iKey)
                {
                    GUIContent buttonLabel = keyHandler.IsDetectingKey(iKey) ?
                                             GUI.MakeLabel("Detecting...") :
                                             GUI.MakeLabel(keyHandler.Keys[iKey].ToString());

                    bool toggleDetecting = GUILayout.Button(buttonLabel,
                                                            InspectorEditor.Skin.ButtonMiddle,
                                                            GUILayout.Width(keyButtonWidth),
                                                            GUILayout.Height(ToggleButtonSize));
                    if (toggleDetecting)
                    {
                        keyHandler.DetectKey(this, !keyHandler.IsDetectingKey(iKey), iKey);
                    }
                }

                GUILayout.BeginVertical(GUILayout.Height(ToggleButtonSize));
                {
                    GUIStyle tmp = new GUIStyle(InspectorEditor.Skin.Button);
                    tmp.fontSize = 6;

                    showDropdownPressed = InspectorGUI.Button(MiscIcon.ContextDropdown,
                                                              true,
                                                              "Add or remove key or reset key to default.",
                                                              GUILayout.Width(16));
                    GUILayout.FlexibleSpace();
                }
                GUILayout.EndVertical();

                UnityEngine.GUI.enabled = true;

                if (showDropdownPressed)
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(GUI.MakeLabel("Reset to default"), false, () =>
                    {
                        if (EditorUtility.DisplayDialog("Reset to default", "Reset key(s) to default?", "OK", "Cancel"))
                        {
                            keyHandler.ResetToDefault();
                        }
                    });
                    menu.AddItem(GUI.MakeLabel("Add key"), false, () =>
                    {
                        keyHandler.Add(KeyCode.None);
                    });

                    if (keyHandler.NumKeyCodes > 1)
                    {
                        menu.AddItem(GUI.MakeLabel("Remove key"), false, () =>
                        {
                            if (EditorUtility.DisplayDialog("Remove key", "Remove key: " + keyHandler[keyHandler.NumKeyCodes - 1].ToString() + "?", "OK", "Cancel"))
                            {
                                keyHandler.Remove(keyHandler.NumKeyCodes - 1);
                            }
                        });
                    }

                    menu.ShowAsContext();
                }
            }
            GUILayout.EndHorizontal();

            if (UnityEngine.GUI.changed)
            {
                EditorUtility.SetDirty(this);
            }
        }