summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Avatar/Conditions/ConditionCommandSeq.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-29 19:39:42 +0800
committerchai <chaifix@163.com>2020-10-29 19:39:42 +0800
commitbdf47cf0fd36a5c858575a805cca70ab623868eb (patch)
treec93691007f656380decbcb93690292e273d4e217 /Assets/Scripts/Avatar/Conditions/ConditionCommandSeq.cs
parent61fbc2cdd8368505c3c8ce893af020463cc2a669 (diff)
*misc
Diffstat (limited to 'Assets/Scripts/Avatar/Conditions/ConditionCommandSeq.cs')
-rw-r--r--Assets/Scripts/Avatar/Conditions/ConditionCommandSeq.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/Assets/Scripts/Avatar/Conditions/ConditionCommandSeq.cs b/Assets/Scripts/Avatar/Conditions/ConditionCommandSeq.cs
new file mode 100644
index 00000000..71a7dbf3
--- /dev/null
+++ b/Assets/Scripts/Avatar/Conditions/ConditionCommandSeq.cs
@@ -0,0 +1,54 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+/// <summary>
+/// 一个command序列,用来触发连击
+/// </summary>
+public class ConditionCommandSeq : ConditionBase
+{
+ List<GamepadButton> m_CommandSeq = new List<GamepadButton>();
+ float m_DeltaTime = 0;
+ List<int> m_LastCmdID = new List<int>();
+
+ List<int> id = new List<int>();
+
+ public ConditionCommandSeq(List<GamepadButton> commandSeq, float maxDeltaTime)
+ {
+ m_CommandSeq.AddRange(commandSeq);
+ m_DeltaTime = maxDeltaTime;
+ }
+
+ public override bool Evaluate()
+ {
+ List<Command> commandRecord = InputManager.Instance.CommandRecord;
+ if (commandRecord == null || commandRecord.Count < m_CommandSeq.Count)
+ return false;
+ id.Clear();
+ for (int i = 1; i < m_CommandSeq.Count; ++i)
+ {
+ GamepadButton button = m_CommandSeq[i];
+ GamepadButton preButton = m_CommandSeq[i-1];
+ int j = commandRecord.Count - m_CommandSeq.Count + i;
+ Command cmd = commandRecord[j];
+ Command preCmd = commandRecord[j-1];
+ if (preCmd.code != preButton || cmd.code != button)
+ return false;
+ if (cmd.time - preCmd.time > m_DeltaTime)
+ return false;
+ id.Add(preCmd.id);
+ if (j == commandRecord.Count - 1)
+ id.Add(cmd.id);
+ }
+
+ //for (int i = 0; i < id.Count; ++i)
+ //{
+ // if (m_LastCmdID.Contains(id[i]))
+ // return false;
+ //}
+ //m_LastCmdID.Clear();
+ //m_LastCmdID.AddRange(id);
+
+ return true;
+ }
+}