예제 #1
0
            private void DrawHotkey(String name, int id, KeyCode main_hotkey)
            {
                HotkeyManager manager = NanoGauges.hotkeyManager;

                Reference <bool> input = manager.GetInput(id);

                KeyCode keycode = manager.GetKeyCode(id);
                bool    enabled = manager.IsEnabled(id);

                GUILayout.BeginHorizontal();

                enabled = GUILayout.Toggle(enabled, " ");
                manager.SetEnabled(id, enabled);

                GUILayout.Label(name, STYLE_NAME);

                if (main_hotkey != KeyCode.None)
                {
                    GUILayout.Label(main_hotkey.ToString().Limit(12), STYLE_CHORD);
                    GUILayout.Label("+", STYLE_LABEL);
                }
                else
                {
                    GUILayout.Label("", STYLE_CHORD);
                    GUILayout.Label("", STYLE_LABEL);
                }

                String text = input.value ? "press" : keycode.ToString().Limit(10);

                Utils.SetTextColor(STYLE_HOTKEY_BUTTON, input.value ? Constants.ORANGE : Color.white);
                if (GUILayout.Button(text, STYLE_HOTKEY_BUTTON))
                {
                    if (input.value)
                    {
                        keycode     = KeyCode.None;
                        input.value = false;
                    }
                    else
                    {
                        input.value = true;
                    }
                }
                if (input.value)
                {
                    if (Input.anyKeyDown)
                    {
                        // do not recognize this input as a hotkey
                        manager.ignoring = true;

                        input.value = false;
                        KeyCode[] keys = Utils.GetPressedKeys();
                        if (keys != null && keys.Length > 0)
                        {
                            keycode = keys[0];
                            if (HotkeyManager.ValidKeyCode(keys[0]))
                            {
                                manager.SetKeyCode(id, keycode);
                            }
                        }
                    }
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }