diff options
Diffstat (limited to 'Assets/Scripts/Avatar/Trigger.cs')
-rw-r--r-- | Assets/Scripts/Avatar/Trigger.cs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/Assets/Scripts/Avatar/Trigger.cs b/Assets/Scripts/Avatar/Trigger.cs index 70a6d0f4..a885327c 100644 --- a/Assets/Scripts/Avatar/Trigger.cs +++ b/Assets/Scripts/Avatar/Trigger.cs @@ -31,17 +31,23 @@ public sealed class Trigger } private ConditionBase m_Condition; - private List<ActionBase> m_ActionChain = new List<ActionBase>(); - + private List<ActionBase> m_ActionChain = new List<ActionBase>();
+
+ private TriggerOnlyOnce m_OnlyOnce; + + private bool m_IsTriggered; + public Trigger(ConditionBase condition, List<ActionBase> actions, TriggerOnlyOnce onlyOnce = TriggerOnlyOnce.Off, TriggerSwallow swallow = TriggerSwallow.On) { - m_Swallow = swallow; + m_OnlyOnce = onlyOnce;
+ m_Swallow = swallow; m_Condition = condition; m_ActionChain.AddRange(actions); } public Trigger(ConditionBase condition, ActionBase action, TriggerOnlyOnce onlyOnce = TriggerOnlyOnce.Off, TriggerSwallow swallow = TriggerSwallow.On) { - m_Swallow = swallow; + m_OnlyOnce = onlyOnce;
+ m_Swallow = swallow; m_Condition = condition; m_ActionChain.Add(action); } @@ -49,8 +55,8 @@ public sealed class Trigger //重置触发器的参数 public void Reset() { - - } + m_IsTriggered = false; + } /// <summary> /// 如果触发执行了,返回true,否则返回false @@ -58,12 +64,15 @@ public sealed class Trigger /// <returns></returns> public bool Update() { + if (m_IsTriggered && m_OnlyOnce == TriggerOnlyOnce.On) + return false; if (m_Condition.Evaluate()) { foreach(var action in m_ActionChain) { action.Execute(); } + m_IsTriggered = true; return true; } return false; |