public static bool GetKey(HK_TYPE hotkey_name) { if (settings.hotkeys.ContainsKey(hotkey_name)) { if (Input.GetKey(settings.hotkeys[hotkey_name].Key)) { return(true); } } return(false); }
public static void ButtonHK(Button button, HK_TYPE key, Func <System.Object, bool> check = null) { if (button == null) { return; } button.gameObject .AddComponent <ActionsComponent>() .With(button) .OnCheck(key) .OnCheck((b) => CheckSelectable((Button)b)) .OnCheck(check) .AddAction(() => ClickButton(button)); }
private static void renderHK_GUI(HK_TYPE key, KeyCode keyCode, string desc) { GUILayout.BeginHorizontal(); GUILayout.Label(desc, new GUILayoutOption[] { GUILayout.MinWidth(200.0f), GUILayout.MaxWidth(200.0f) }); string text = (Main.binding_key && Main.current_binding_key == key) ? "请按下需要的按键" : keyCode.ToString(); bool ret = GUILayout.Button(text, new GUILayoutOption[] { GUILayout.MinWidth(200.0f), GUILayout.MaxWidth(200.0f) }); if (ret) { // 点击绑定按钮时正处于绑定事件中 if (Main.binding_key) { // 若两次的按钮相同,则判断为清空快捷键 if (key == Main.current_binding_key) { Main.settings.hotkeys[Main.current_binding_key] = KeyCode.None; Main.binding_key = false; Main.settings.Save(); } // 若两次的按钮不同,则上次的按钮对应的快捷键还原,当前的按钮开始进入绑定状态 else { Main.settings.hotkeys[Main.current_binding_key] = Main.last_key_code; Main.current_binding_key = key; Main.last_key_code = keyCode; binding_key = true; } } // 点击绑定按钮时不处于绑定事件中,则当前按钮开始进入绑定状态 else { Main.current_binding_key = key; Main.last_key_code = keyCode; binding_key = true; } } GUILayout.EndHorizontal(); }
private static void renderHK_GUI(HK_TYPE key, KeyValuePair <KeyCode, string> value) { GUILayout.BeginHorizontal(); GUILayout.Label(value.Value, new GUILayoutOption[] { GUILayout.MinWidth(200.0f), GUILayout.MaxWidth(200.0f) }); var ret = GUILayout.Button(value.Key == KeyCode.None ? "请按下需要的按键" : value.Key.ToString(), new GUILayoutOption[] { GUILayout.MinWidth(200.0f), GUILayout.MaxWidth(200.0f) }); if (ret == true) { if (binding_key == true) { //重复绑定 //恢复上次绑定key的默认值 settings.hotkeys[current_binding_key] = new KeyValuePair <KeyCode, string>(last_key_code, settings.hotkeys[current_binding_key].Value); } //保存临时值 current_binding_key = key; last_key_code = value.Key; settings.hotkeys[key] = new KeyValuePair <KeyCode, string>(KeyCode.None, value.Value); binding_key = true; } GUILayout.EndHorizontal(); }
static void OnGUI(UnityModManager.ModEntry modEntry) { processKeyPress(); GUILayout.BeginVertical("box", new GUILayoutOption[] { GUILayout.MinWidth(700.0f), GUILayout.MaxWidth(700.0f) }); var keys = settings.hotkeys.Keys.ToArray(); for (int index = 0; index < keys.Length; index++) { HK_TYPE key = keys[index]; KeyCode keyCode = settings.hotkeys[key]; string desc = Settings.hotkeyNames[key]; // Do not allow modifying the close key if (key == HK_TYPE.CLOSE) { settings.hotkeys[key] = KeyCode.Escape; } else { renderHK_GUI(key, keyCode, desc); } } GUILayout.EndVertical(); }
static void OnGUI(UnityModManager.ModEntry modEntry) { processKeyPress(); GUILayout.BeginVertical("box"); settings.enable_close = GUILayout.Toggle(settings.enable_close, "是否使用本Mod的Esc/鼠标右键关闭功能(需要重启游戏生效)"); settings.escAsLastOption = GUILayout.Toggle(settings.escAsLastOption, "是否在对话窗口使用Esc/鼠标右键选择最后一个选项"); settings.useNumpadKeysInMessageWindow = GUILayout.Toggle(settings.useNumpadKeysInMessageWindow, "是否在对话窗口增加小键盘选择功能"); GUILayout.Label("战斗中释放轻功技能的装饰键"); settings.qinggong_modifier_key = (MODIFIER_KEY_TYPE)GUILayout.SelectionGrid((int)settings.qinggong_modifier_key, new string[] { "Shift", "Ctrl", "Alt" }, 3); GUILayout.Label("战斗中释放绝技的装饰键"); settings.special_modifierkey = (MODIFIER_KEY_TYPE)GUILayout.SelectionGrid((int)settings.special_modifierkey, new string[] { "Shift", "Ctrl", "Alt" }, 3); GUILayout.EndVertical(); GUILayout.BeginVertical("box", new GUILayoutOption[] { GUILayout.MinWidth(700.0f), GUILayout.MaxWidth(700.0f) }); var keys = settings.hotkeys.Keys.ToArray(); for (int index = 0; index < keys.Length; index++) { HK_TYPE key = keys[index]; KeyCode keyCode = settings.hotkeys[key]; string desc = Settings.hotkeyNames[key]; // Do not allow modifying the close key if (key == HK_TYPE.HK_CLOSE) { settings.hotkeys[key] = KeyCode.Escape; } else { renderHK_GUI(key, keyCode, desc); } } GUILayout.EndVertical(); }
public static bool GetKey(HK_TYPE key) { return(settings.hotkeys.ContainsKey(key) && Input.GetKey(settings.hotkeys[key])); }
public ActionsComponent OnCheck(HK_TYPE key) { return(OnCheck(_ => Main.GetKeyDown(key))); }