From f8fc518a4434d266ef1c7a471c70e440488f62b4 Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Thu, 12 Sep 2024 15:10:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Script/UI/CommandDispatcher.meta | 8 ++ .../UI/CommandDispatcher/CommandDispatcher.cs | 86 +++++++++++++++++++ .../CommandDispatcher.cs.meta | 0 .../CommandExcuter.cs} | 81 +---------------- .../CommandDispatcher/CommandExcuter.cs.meta | 11 +++ 5 files changed, 106 insertions(+), 80 deletions(-) create mode 100644 AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher.meta create mode 100644 AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs rename AxibugEmuOnline.Client/Assets/Script/UI/{ => CommandDispatcher}/CommandDispatcher.cs.meta (100%) rename AxibugEmuOnline.Client/Assets/Script/UI/{CommandDispatcher.cs => CommandDispatcher/CommandExcuter.cs} (56%) create mode 100644 AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandExcuter.cs.meta diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher.meta b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher.meta new file mode 100644 index 0000000..50b7105 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1e5c9fb1d636a5d43b09c7db07044b4f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs new file mode 100644 index 0000000..ebe7894 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs @@ -0,0 +1,86 @@ +using AxibugEmuOnline.Client.UI; +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace AxibugEmuOnline.Client +{ + public class CommandDispatcher : MonoBehaviour + { + public static CommandDispatcher Instance { get; private set; } + + List m_register = new List(); + Dictionary m_keyMapper = new Dictionary(); + + private void Awake() + { + Instance = this; + + m_keyMapper.Add(KeyCode.A, EnumCommand.SelectItemLeft); + m_keyMapper.Add(KeyCode.D, EnumCommand.SelectItemRight); + m_keyMapper.Add(KeyCode.W, EnumCommand.SelectItemUp); + m_keyMapper.Add(KeyCode.S, EnumCommand.SelectItemDown); + m_keyMapper.Add(KeyCode.K, EnumCommand.Enter); + m_keyMapper.Add(KeyCode.L, EnumCommand.Back); + m_keyMapper.Add(KeyCode.I, EnumCommand.OptionMenu); + + m_keyMapper.Add(KeyCode.LeftArrow, EnumCommand.SelectItemLeft); + m_keyMapper.Add(KeyCode.RightArrow, EnumCommand.SelectItemRight); + m_keyMapper.Add(KeyCode.UpArrow, EnumCommand.SelectItemUp); + m_keyMapper.Add(KeyCode.DownArrow, EnumCommand.SelectItemDown); + m_keyMapper.Add(KeyCode.Return, EnumCommand.Enter); + m_keyMapper.Add(KeyCode.Escape, EnumCommand.Back); + m_keyMapper.Add(KeyCode.RightShift, EnumCommand.OptionMenu); + m_keyMapper.Add(KeyCode.LeftShift, EnumCommand.OptionMenu); + } + + private void OnDestroy() + { + Instance = null; + } + + public void RegistController(CommandExecuter controller) + { + if (m_register.Contains(controller)) { return; } + + m_register.Add(controller); + } + + public void UnRegistController(CommandExecuter menuItemController) + { + m_register.Remove(menuItemController); + } + + readonly List oneFrameRegister = new List(); + private void Update() + { + foreach (var item in m_keyMapper) + { + if (Input.GetKeyDown(item.Key)) + { + oneFrameRegister.Clear(); + oneFrameRegister.AddRange(m_register); + + for (int i = 0; i < oneFrameRegister.Count; i++) + { + var controller = oneFrameRegister[i]; + if (!controller.Enable) continue; + controller.ExecuteCommand(item.Value, false); + } + } + if (Input.GetKeyUp(item.Key)) + { + oneFrameRegister.Clear(); + oneFrameRegister.AddRange(m_register); + + for (int i = 0; i < oneFrameRegister.Count; i++) + { + var controller = oneFrameRegister[i]; + if (!controller.Enable) continue; + controller.ExecuteCommand(item.Value, true); + } + } + } + } + } +} diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher.cs.meta b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs.meta similarity index 100% rename from AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher.cs.meta rename to AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs.meta diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher.cs b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandExcuter.cs similarity index 56% rename from AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher.cs rename to AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandExcuter.cs index 492e28d..12db380 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandExcuter.cs @@ -1,89 +1,10 @@ using AxibugEmuOnline.Client.UI; -using System; +using System.Collections; using System.Collections.Generic; using UnityEngine; namespace AxibugEmuOnline.Client { - public class CommandDispatcher : MonoBehaviour - { - public static CommandDispatcher Instance { get; private set; } - - List m_register = new List(); - Dictionary m_keyMapper = new Dictionary(); - - private void Awake() - { - Instance = this; - - m_keyMapper.Add(KeyCode.A, EnumCommand.SelectItemLeft); - m_keyMapper.Add(KeyCode.D, EnumCommand.SelectItemRight); - m_keyMapper.Add(KeyCode.W, EnumCommand.SelectItemUp); - m_keyMapper.Add(KeyCode.S, EnumCommand.SelectItemDown); - m_keyMapper.Add(KeyCode.K, EnumCommand.Enter); - m_keyMapper.Add(KeyCode.L, EnumCommand.Back); - m_keyMapper.Add(KeyCode.I, EnumCommand.OptionMenu); - - m_keyMapper.Add(KeyCode.LeftArrow, EnumCommand.SelectItemLeft); - m_keyMapper.Add(KeyCode.RightArrow, EnumCommand.SelectItemRight); - m_keyMapper.Add(KeyCode.UpArrow, EnumCommand.SelectItemUp); - m_keyMapper.Add(KeyCode.DownArrow, EnumCommand.SelectItemDown); - m_keyMapper.Add(KeyCode.Return, EnumCommand.Enter); - m_keyMapper.Add(KeyCode.Escape, EnumCommand.Back); - m_keyMapper.Add(KeyCode.RightShift, EnumCommand.OptionMenu); - m_keyMapper.Add(KeyCode.LeftShift, EnumCommand.OptionMenu); - } - - private void OnDestroy() - { - Instance = null; - } - - public void RegistController(CommandExecuter controller) - { - if (m_register.Contains(controller)) { return; } - - m_register.Add(controller); - } - - public void UnRegistController(CommandExecuter menuItemController) - { - m_register.Remove(menuItemController); - } - - readonly List oneFrameRegister = new List(); - private void Update() - { - foreach (var item in m_keyMapper) - { - if (Input.GetKeyDown(item.Key)) - { - oneFrameRegister.Clear(); - oneFrameRegister.AddRange(m_register); - - for (int i = 0; i < oneFrameRegister.Count; i++) - { - var controller = oneFrameRegister[i]; - if (!controller.Enable) continue; - controller.ExecuteCommand(item.Value, false); - } - } - if (Input.GetKeyUp(item.Key)) - { - oneFrameRegister.Clear(); - oneFrameRegister.AddRange(m_register); - - for (int i = 0; i < oneFrameRegister.Count; i++) - { - var controller = oneFrameRegister[i]; - if (!controller.Enable) continue; - controller.ExecuteCommand(item.Value, true); - } - } - } - } - } - public abstract class CommandExecuter : MonoBehaviour { private PulseInvoker m_pulsInvoker_Left; diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandExcuter.cs.meta b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandExcuter.cs.meta new file mode 100644 index 0000000..677ba87 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandExcuter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8506406a7119fff468b4ce029101f81a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: