diff options
author | chai <chaifix@163.com> | 2021-08-29 12:54:37 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-08-29 12:54:37 +0800 |
commit | de78537f8edc6cb162ba58520956255f7e53769d (patch) | |
tree | 1bf05e3910149bffb79fb0c96e9ef1e28ea126e1 /Assets/Scripts/Input/InputManager.cs | |
parent | e2284510c40e2d637c28108b50df2e403d51ec1c (diff) |
*轴向改为xy
Diffstat (limited to 'Assets/Scripts/Input/InputManager.cs')
-rw-r--r-- | Assets/Scripts/Input/InputManager.cs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/Assets/Scripts/Input/InputManager.cs b/Assets/Scripts/Input/InputManager.cs index b5e3d8a1..62fd5f91 100644 --- a/Assets/Scripts/Input/InputManager.cs +++ b/Assets/Scripts/Input/InputManager.cs @@ -2,12 +2,22 @@ using System.Collections.Generic;
using UnityEngine;
+public struct InputCommand
+{
+ public KeyCode key;
+ public float time;
+}
+
// 处理输入逻辑,不涉及读取输入,只处理逻辑
public class InputManager : SingletonMB<InputManager>
{
PCController _pc;
+ List<InputCommand> m_CommandQueue = new List<InputCommand>();
+
+ const float threshold = 3;
+
PCController pc
{
get
@@ -49,4 +59,57 @@ public class InputManager : SingletonMB<InputManager> pc.unitState.ChangeState(UnitState.EUnitState.Attack, new UnitState.SkillParam());
}
+ 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)
+ {
+ if (keys.Length > m_CommandQueue.Count)
+ 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);
+ return true;
+ }
+
}
|