From b1b14c45ce95dcf7b81867d68d6006345d98959e Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 15 Oct 2020 05:41:48 +0800 Subject: *input system --- Assets/Scripts/Input/Command.cs | 34 +++++++++++++++ Assets/Scripts/Input/Command.cs.meta | 11 +++++ Assets/Scripts/Input/CommandType.cs | 21 --------- Assets/Scripts/Input/CommandType.cs.meta | 11 ----- Assets/Scripts/Input/InputManager.cs | 74 +++++++++++++++++++++++++++----- 5 files changed, 108 insertions(+), 43 deletions(-) create mode 100644 Assets/Scripts/Input/Command.cs create mode 100644 Assets/Scripts/Input/Command.cs.meta delete mode 100644 Assets/Scripts/Input/CommandType.cs delete mode 100644 Assets/Scripts/Input/CommandType.cs.meta (limited to 'Assets/Scripts/Input') diff --git a/Assets/Scripts/Input/Command.cs b/Assets/Scripts/Input/Command.cs new file mode 100644 index 00000000..5ac2c2a0 --- /dev/null +++ b/Assets/Scripts/Input/Command.cs @@ -0,0 +1,34 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +public enum CommandCode +{ + Blank, + + // 方向键 + Left, + Right, + Up, + Down, + + // 操作键 + Triangle, // △ + Cross, // × + Square, // □ + Circle, // ○ +} + +public struct Command +{ + public CommandCode code; // 指令码 + public float time; // 触发时间 + + public Command(CommandCode code, float time) + { + this.code = code; + this.time = time; + } +} + diff --git a/Assets/Scripts/Input/Command.cs.meta b/Assets/Scripts/Input/Command.cs.meta new file mode 100644 index 00000000..f2802802 --- /dev/null +++ b/Assets/Scripts/Input/Command.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e105d6d96dd08e8499e6a4254d289e99 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Input/CommandType.cs b/Assets/Scripts/Input/CommandType.cs deleted file mode 100644 index 3c537383..00000000 --- a/Assets/Scripts/Input/CommandType.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - - -public enum Command -{ - // 方向键 - Left, - Right, - Top, - Bottom, - - // 操作键 - Triangle, // △ - Cross, // × - Square, // □ - Circle, // ○ -} - - diff --git a/Assets/Scripts/Input/CommandType.cs.meta b/Assets/Scripts/Input/CommandType.cs.meta deleted file mode 100644 index f2802802..00000000 --- a/Assets/Scripts/Input/CommandType.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 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 { - // Start is called before the first frame update - void Start() - { - - } + private List m_CommandRecord; + private Command m_CurrentCommand; + + public void Init() + { + m_CommandRecord = new List(); + 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() - { - - } } -- cgit v1.1-26-g67d0