Exemple #1
0
 public static bool TargetEditorOnInspectorGUI <T>(T target, GUISkin skin) where T : class
 {
     return(KeyHandler.HandleDetectKeyOnGUI(target, Event.current));
 }
Exemple #2
0
        private void HandleKeyHandlerGUI(GUIContent name, Utils.KeyHandler keyHandler, GUISkin skin)
        {
            const int keyButtonWidth  = 90;
            const int keyButtonHeight = 18;

            GUILayout.BeginHorizontal();
            {
                keyHandler.Enable = GUI.Toggle(name,
                                               keyHandler.Enable,
                                               skin.button,
                                               GUI.Align(skin.label, TextAnchor.MiddleLeft),
                                               new GUILayoutOption[] { GUILayout.Width(keyButtonHeight), GUILayout.Height(keyButtonHeight) },
                                               new GUILayoutOption[] { GUILayout.Height(keyButtonHeight) });
                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(keyButtonHeight));
                    if (toggleDetecting)
                    {
                        keyHandler.DetectKey(this, !keyHandler.IsDetectingKey(iKey), iKey);
                    }
                }

                Rect dropDownButtonRect = new Rect();
                GUILayout.BeginVertical(GUILayout.Height(keyButtonHeight));
                {
                    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);
            }
        }
Exemple #3
0
        public static void TargetEditorEnable <T>(T target, GUISkin skin) where T : class
        {
            KeyHandler.HandleDetectKeyOnEnable(target);

            Tools.Tool.ActivateToolGivenTarget(target);
        }