From fee35151213939d61d2dbd9d6a0ba71ac93b91cf Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 17 Oct 2020 15:39:34 +0800 Subject: =?UTF-8?q?+=20=E8=BF=9E=E5=87=BB=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Input/InputManager.cs | 66 ++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 22 deletions(-) (limited to 'Assets/Scripts/Input/InputManager.cs') diff --git a/Assets/Scripts/Input/InputManager.cs b/Assets/Scripts/Input/InputManager.cs index 25daf848..771032a8 100644 --- a/Assets/Scripts/Input/InputManager.cs +++ b/Assets/Scripts/Input/InputManager.cs @@ -20,36 +20,36 @@ public class InputManager : Singleton public void Init() { m_CommandRecord = new List(); - m_CurrentCommand = new Command(CommandCode.Blank, 0); + m_CurrentCommand = new Command(GamepadButton.Blank, 0); } public void Update() { - CommandCode cmd = CommandCode.Blank; + GamepadButton cmd = GamepadButton.Blank; // 移动 if (Input.GetKeyDown("w")) - cmd = CommandCode.Up; + cmd = GamepadButton.Up; if (Input.GetKeyDown("s")) - cmd = CommandCode.Down; + cmd = GamepadButton.Down; if (Input.GetKeyDown("a")) - cmd = CommandCode.Left; + cmd = GamepadButton.Left; if (Input.GetKeyDown("d")) - cmd = CommandCode.Right; + cmd = GamepadButton.Right; // 动作 if (Input.GetKeyDown("j")) - cmd = CommandCode.Circle; + cmd = GamepadButton.Circle; if (Input.GetKeyDown("k")) - cmd = CommandCode.Triangle; + cmd = GamepadButton.Triangle; if (Input.GetKeyDown("l")) - cmd = CommandCode.Square; + cmd = GamepadButton.Square; if(Input.GetKeyDown("u")) - cmd = CommandCode.Cross; + cmd = GamepadButton.Cross; - if(cmd != CommandCode.Blank) + if(cmd != GamepadButton.Blank) { float time = Time.time; Command command = new Command(cmd, time); - Debug.Log(CommandToString(command)); + //Debug.Log(CommandToString(command)); m_CurrentCommand = command; m_CommandRecord.Add(command); @@ -57,24 +57,24 @@ public class InputManager : Singleton if(m_CommandRecord.Count > 10) m_CommandRecord.RemoveRange(0, m_CommandRecord.Count - 10); } - else if(m_CurrentCommand.code != CommandCode.Blank) + else if(m_CurrentCommand.code != GamepadButton.Blank) { m_CurrentCommand = Command.Blank; } } - string CommandCodeToString(CommandCode cmd) + string CommandCodeToString(GamepadButton cmd) { switch(cmd) { - case CommandCode.Left: return "←"; - case CommandCode.Right: return "→"; - case CommandCode.Up: return "↑"; - case CommandCode.Down: return "↓"; - case CommandCode.Circle: return "○"; - case CommandCode.Triangle: return "△"; - case CommandCode.Square: return "□"; - case CommandCode.Cross: return "×"; + 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"; } } @@ -85,4 +85,26 @@ public class InputManager : Singleton 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 ""; + } + + public bool IsButtonHold(GamepadButton button) + { + return Input.GetKey(GetGamepadButtonKey(button)); + } + } -- cgit v1.1-26-g67d0