From 79ff94365b572d0e64ba945dcef2641ee508faa7 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 6 Nov 2020 20:41:04 +0800 Subject: =?UTF-8?q?*=E7=A9=BA=E4=B8=AD=E6=94=BB=E5=87=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Avatar/Trigger.cs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'Assets/Scripts/Avatar/Trigger.cs') 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 m_ActionChain = new List(); - + private List m_ActionChain = new List(); + + private TriggerOnlyOnce m_OnlyOnce; + + private bool m_IsTriggered; + public Trigger(ConditionBase condition, List 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; + } /// /// 如果触发执行了,返回true,否则返回false @@ -58,12 +64,15 @@ public sealed class Trigger /// 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; -- cgit v1.1-26-g67d0