summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Input/InputManager.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-17 15:39:34 +0800
committerchai <chaifix@163.com>2020-10-17 15:39:34 +0800
commitfee35151213939d61d2dbd9d6a0ba71ac93b91cf (patch)
tree3aa986e27f36e47242b9a12b7e7b6a8d5d8c0fc8 /Assets/Scripts/Input/InputManager.cs
parentf99c4d56cf95c563e95d3965ffd6d8ba33b660ee (diff)
+ 连击测试
Diffstat (limited to 'Assets/Scripts/Input/InputManager.cs')
-rw-r--r--Assets/Scripts/Input/InputManager.cs66
1 files changed, 44 insertions, 22 deletions
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<InputManager>
public void Init()
{
m_CommandRecord = new List<Command>();
- 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<InputManager>
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<InputManager>
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));
+ }
+
}