From 22891bf59032ba88262824255a706d652031384b Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 10 Mar 2022 14:07:40 +0800 Subject: * move folder --- Assets/Scripts/Input/Command.cs | 38 ------- Assets/Scripts/Input/Command.cs.meta | 11 -- Assets/Scripts/Input/InputManager.cs | 99 ----------------- Assets/Scripts/Input/InputManager.cs.meta | 11 -- Assets/Scripts/Input/_InputManager.cs | 164 ----------------------------- Assets/Scripts/Input/_InputManager.cs.meta | 11 -- 6 files changed, 334 deletions(-) delete mode 100644 Assets/Scripts/Input/Command.cs delete mode 100644 Assets/Scripts/Input/Command.cs.meta delete mode 100644 Assets/Scripts/Input/InputManager.cs delete mode 100644 Assets/Scripts/Input/InputManager.cs.meta delete mode 100644 Assets/Scripts/Input/_InputManager.cs delete mode 100644 Assets/Scripts/Input/_InputManager.cs.meta (limited to 'Assets/Scripts/Input') diff --git a/Assets/Scripts/Input/Command.cs b/Assets/Scripts/Input/Command.cs deleted file mode 100644 index 7ef6c9eb..00000000 --- a/Assets/Scripts/Input/Command.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - - -public enum GamepadButton -{ - Blank, - - // 方向键 - Left, - Right, - Up, - Down, - - // 操作键 - Triangle, // △ - Cross, // × - Square, // □ - Circle, // ○ -} - -public struct Command -{ - public GamepadButton code; // 指令码 - public float time; // 触发时间 - public int id; - - public static Command Blank = new Command(GamepadButton.Blank, 0); - - public Command(GamepadButton code, float time) - { - this.code = code; - this.time = time; - this.id = UIDManager.Acquire(); - } -} - diff --git a/Assets/Scripts/Input/Command.cs.meta b/Assets/Scripts/Input/Command.cs.meta deleted file mode 100644 index f2802802..00000000 --- a/Assets/Scripts/Input/Command.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e105d6d96dd08e8499e6a4254d289e99 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Input/InputManager.cs b/Assets/Scripts/Input/InputManager.cs deleted file mode 100644 index 06e4f02f..00000000 --- a/Assets/Scripts/Input/InputManager.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public struct InputCommand -{ - public KeyCode key; - public float time; -} - -// 处理输入逻辑,不涉及读取输入,只处理逻辑 -public class InputManager : SingletonMB -{ - - PCController _pc; - - List m_CommandQueue = new List(); - - const float threshold = 3; - - PCController pc - { - get - { - if (_pc == null) - _pc = PCController.instance; - return _pc; - } - } - - public void OnUpdate() - { - foreach (KeyCode vKey in System.Enum.GetValues(typeof(KeyCode))) - { - if (Input.GetKeyDown(vKey)) - { - InputCommand cmd = new InputCommand(); - cmd.key = vKey; - cmd.time = Time.time; - m_CommandQueue.Add(cmd); - - //Debug.Log(cmd.time); - string cmdStr = ""; - m_CommandQueue.ForEach(s => cmdStr += s.key.ToString() + ","); - Debug.Log(cmdStr); - } - } - float curTime = Time.time; - int removeCount = 0; - for(int i = 0; i < m_CommandQueue.Count; ++i) - { - if(curTime - m_CommandQueue[i].time > threshold) - { - removeCount++; - } - } - m_CommandQueue.RemoveRange(0, removeCount); - } - - public bool TryCommand(float interval = 0.5f, params KeyCode[] keys) - { - return TryCommand(interval, true, keys); - - } - - public bool TryCommand(float interval = 0.5f, bool checkInput = false, params KeyCode[] keys) - { - if (keys.Length > m_CommandQueue.Count) - return false; - if (checkInput && !Input.GetKey(keys[keys.Length - 1])) - return false; - int count = m_CommandQueue.Count; - float preTime = m_CommandQueue[count - keys.Length].time; - for (int i = 0; i < keys.Length; ++i) - { - if (keys[i] == m_CommandQueue[i + count - keys.Length].key) - { - if (m_CommandQueue[i + count - keys.Length].time - preTime > interval) - { - return false; - } - preTime = m_CommandQueue[i + count - keys.Length].time; - } - else - { - return false; - } - } - //m_CommandQueue.RemoveRange(count - keys.Length, keys.Length); - m_CommandQueue.Clear(); // 清理 - return true; - } - - public void ClearCommand() - { - m_CommandQueue.Clear(); - } - -} diff --git a/Assets/Scripts/Input/InputManager.cs.meta b/Assets/Scripts/Input/InputManager.cs.meta deleted file mode 100644 index c426b3c5..00000000 --- a/Assets/Scripts/Input/InputManager.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 16f7a980b8509a146971d6ad5133b63a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Input/_InputManager.cs b/Assets/Scripts/Input/_InputManager.cs deleted file mode 100644 index a9d120e4..00000000 --- a/Assets/Scripts/Input/_InputManager.cs +++ /dev/null @@ -1,164 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class _InputManager : Singleton<_InputManager> -{ - private List m_CommandRecord; - public List CommandRecord - { - get - { - return m_CommandRecord; - } - } - private readonly int kCommandRecords = 10; - - // 本帧内的指令,会在下一帧被清空 - private Command m_CurrentCommand; - public Command CurrentCommand - { - get - { - return m_CurrentCommand; - } - } - - private enum Axis { Up, Down, Left, Right}; - - private bool[] m_Axis = new bool[4] { false, false, false, false}; - - public void Init() - { - m_CommandRecord = new List(); - m_CurrentCommand = new Command(GamepadButton.Blank, 0); - } - - private bool GetAxis(Axis axis) - { - return false; - bool axisRaw = false; - switch (axis) - { - case Axis.Left: axisRaw = Input.GetAxisRaw("Horizontal") == -1; break; - case Axis.Right: axisRaw = Input.GetAxisRaw("Horizontal") == 1; break; - case Axis.Down: axisRaw = Input.GetAxisRaw("Vertical") == -1; break; - case Axis.Up: axisRaw = Input.GetAxisRaw("Vertical") == 1; break; - } - if (axisRaw) - { - if(!m_Axis[(int)axis]) - { - m_Axis[(int)axis] = true; - return true; - } - return false; - } - else - { - m_Axis[(int)axis] = false; - return false; - } - } - - public void Update() - { - GamepadButton cmd = GamepadButton.Blank; - // 移动 - if (Input.GetKeyDown("w") || GetAxis(Axis.Up)) - cmd = GamepadButton.Up; - if (Input.GetKeyDown("s") || GetAxis(Axis.Down)) - cmd = GamepadButton.Down; - if (Input.GetKeyDown("a") || GetAxis(Axis.Left)) - cmd = GamepadButton.Left; - if (Input.GetKeyDown("d") || GetAxis(Axis.Right)) - cmd = GamepadButton.Right; - // 动作 - if (Input.GetKeyDown("j") || Input.GetKeyDown(KeyCode.Joystick1Button2)) - cmd = GamepadButton.Circle; - if (Input.GetKeyDown("k") || Input.GetKeyDown(KeyCode.Joystick1Button0)) - cmd = GamepadButton.Triangle; - if (Input.GetKeyDown("l") || Input.GetKeyDown(KeyCode.Joystick1Button1)) - cmd = GamepadButton.Square; - if (Input.GetKeyDown("u") || Input.GetKeyDown(KeyCode.Joystick1Button3)) - cmd = GamepadButton.Cross; - - if(cmd != GamepadButton.Blank) - { - float time = Time.time; - Command command = new Command(cmd, time); - //Debug.Log(CommandToString(command)); - - m_CurrentCommand = command; - m_CommandRecord.Add(command); - - if(m_CommandRecord.Count > 10) - m_CommandRecord.RemoveRange(0, m_CommandRecord.Count - 10); - } - else if(m_CurrentCommand.code != GamepadButton.Blank) - { - m_CurrentCommand = Command.Blank; - } - } - - string CommandCodeToString(GamepadButton cmd) - { - switch(cmd) - { - case GamepadButton.Left: return "←"; - case GamepadButton.Right: return "→"; - case GamepadButton.Up: return "↑"; - case GamepadButton.Down: return "↓"; - case GamepadButton.Circle: return "○"; - case GamepadButton.Triangle: return "△"; - case GamepadButton.Square: return "□"; - case GamepadButton.Cross: return "×"; - default: return "Unknown"; - } - } - - string CommandToString(Command cmd) - { - string sign = CommandCodeToString(cmd.code); - return sign + " " + cmd.time + "s" + " " + cmd.id; - } - - string GetGamepadButtonKey(GamepadButton button) - { - switch (button) - { - case GamepadButton.Blank: return ""; - case GamepadButton.Up: return "w"; - case GamepadButton.Down: return "s"; - case GamepadButton.Left: return "a"; - case GamepadButton.Right: return "d"; - case GamepadButton.Circle: return "j"; - case GamepadButton.Triangle: return "k"; - case GamepadButton.Square: return "l"; - case GamepadButton.Cross: return "u"; - } - return ""; - } - - bool GetGamepadButtonState(GamepadButton button) - { - switch (button) - { - case GamepadButton.Up: return m_Axis[(int)Axis.Up]; - case GamepadButton.Down: return m_Axis[(int)Axis.Down]; - case GamepadButton.Left: return m_Axis[(int)Axis.Left]; - case GamepadButton.Right: return m_Axis[(int)Axis.Right]; - case GamepadButton.Circle: return Input.GetKey(KeyCode.Joystick1Button2); - case GamepadButton.Triangle: return Input.GetKey(KeyCode.Joystick1Button0); - case GamepadButton.Square: return Input.GetKey(KeyCode.Joystick1Button1); - case GamepadButton.Cross: return Input.GetKey(KeyCode.Joystick1Button3); - } - return false; - } - - public bool IsButtonHold(GamepadButton button) - { - return Input.GetKey(GetGamepadButtonKey(button)) || GetGamepadButtonState(button); - } - -} diff --git a/Assets/Scripts/Input/_InputManager.cs.meta b/Assets/Scripts/Input/_InputManager.cs.meta deleted file mode 100644 index 234b6d17..00000000 --- a/Assets/Scripts/Input/_InputManager.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 26195ae7cb9459e498256c387da7273e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: -- cgit v1.1-26-g67d0