summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Input/InputManager.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2022-03-10 14:07:40 +0800
committerchai <chaifix@163.com>2022-03-10 14:07:40 +0800
commit22891bf59032ba88262824255a706d652031384b (patch)
tree7595439ba9966c9402d37e37cee5e8cf098757d5 /Assets/Scripts/Input/InputManager.cs
parent8b04ea73e540067f83870b61d89db4868fea5e8a (diff)
* move folder
Diffstat (limited to 'Assets/Scripts/Input/InputManager.cs')
-rw-r--r--Assets/Scripts/Input/InputManager.cs99
1 files changed, 0 insertions, 99 deletions
diff --git a/Assets/Scripts/Input/InputManager.cs b/Assets/Scripts/Input/InputManager.cs
deleted file mode 100644
index 06e4f02f..00000000
--- a/Assets/Scripts/Input/InputManager.cs
+++ /dev/null
@@ -1,99 +0,0 @@
-using System.Collections;
-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
- {
- if (_pc == null)
- _pc = PCController.instance;
- return _pc;
- }
- }
-
- 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)
- {
- return TryCommand(interval, true, keys);
-
- }
-
- public bool TryCommand(float interval = 0.5f, bool checkInput = false, params KeyCode[] keys)
- {
- if (keys.Length > m_CommandQueue.Count)
- return false;
- if (checkInput && !Input.GetKey(keys[keys.Length - 1]))
- 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);
- m_CommandQueue.Clear(); // 清理
- return true;
- }
-
- public void ClearCommand()
- {
- m_CommandQueue.Clear();
- }
-
-}