diff options
author | chai <chaifix@163.com> | 2020-10-15 05:41:48 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-10-15 05:41:48 +0800 |
commit | b1b14c45ce95dcf7b81867d68d6006345d98959e (patch) | |
tree | 50f9fb13aea169c1db0213c2c068d19771f4aab5 /Assets/Scripts/Input/InputManager.cs | |
parent | 0d221e6c05d59d812d494f05b9916d85650032eb (diff) |
*input system
Diffstat (limited to 'Assets/Scripts/Input/InputManager.cs')
-rw-r--r-- | Assets/Scripts/Input/InputManager.cs | 74 |
1 files changed, 63 insertions, 11 deletions
diff --git a/Assets/Scripts/Input/InputManager.cs b/Assets/Scripts/Input/InputManager.cs index 098190bc..c1a26327 100644 --- a/Assets/Scripts/Input/InputManager.cs +++ b/Assets/Scripts/Input/InputManager.cs @@ -2,17 +2,69 @@ using System.Collections.Generic;
using UnityEngine;
-public class InputManager : MonoBehaviour
+public class InputManager : Singleton<InputManager>
{
- // Start is called before the first frame update
- void Start()
- {
-
- }
+ private List<Command> m_CommandRecord;
+ private Command m_CurrentCommand;
+
+ public void Init()
+ {
+ m_CommandRecord = new List<Command>();
+ m_CurrentCommand = new Command(CommandCode.Blank, 0);
+ }
+
+ public void Update()
+ {
+ CommandCode cmd = CommandCode.Blank;
+ // 移动
+ if (Input.GetKeyDown("w"))
+ cmd = CommandCode.Up;
+ if (Input.GetKeyDown("s"))
+ cmd = CommandCode.Down;
+ if (Input.GetKeyDown("a"))
+ cmd = CommandCode.Left;
+ if (Input.GetKeyDown("d"))
+ cmd = CommandCode.Right;
+ // 动作
+ if (Input.GetKeyDown("j"))
+ cmd = CommandCode.Circle;
+ if (Input.GetKeyDown("k"))
+ cmd = CommandCode.Triangle;
+ if (Input.GetKeyDown("l"))
+ cmd = CommandCode.Square;
+ if(Input.GetKeyDown("u"))
+ cmd = CommandCode.Cross;
+
+ if(cmd != CommandCode.Blank)
+ {
+ float time = Time.time;
+ Command command = new Command(cmd, time);
+ Debug.Log(CommandToString(command));
+ m_CurrentCommand = command;
+ m_CommandRecord.Add(command);
+ }
+ }
+
+ string CommandCodeToString(CommandCode 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 "×";
+ default: return "Unknown";
+ }
+ }
+
+ string CommandToString(Command cmd)
+ {
+ string sign = CommandCodeToString(cmd.code);
+ return sign + " " + cmd.time + "s";
+ }
- // Update is called once per frame
- void Update()
- {
-
- }
}
|