diff options
Diffstat (limited to 'Assets/Scripts/Input/InputManager.cs')
-rw-r--r-- | Assets/Scripts/Input/InputManager.cs | 59 |
1 files changed, 35 insertions, 24 deletions
diff --git a/Assets/Scripts/Input/InputManager.cs b/Assets/Scripts/Input/InputManager.cs index 4ad6ec02..6b200462 100644 --- a/Assets/Scripts/Input/InputManager.cs +++ b/Assets/Scripts/Input/InputManager.cs @@ -59,30 +59,41 @@ public class InputManager : SingletonMB<InputManager> public bool TryCommand(float interval = 0.5f, params KeyCode[] keys)
{
- if (keys.Length > m_CommandQueue.Count)
- return false;
- if (!Input.GetKey(keys[keys.Length - 1]))
+ 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;
- 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;
- }
+ 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();
+ }
}
|