From bdf47cf0fd36a5c858575a805cca70ab623868eb Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 29 Oct 2020 19:39:42 +0800 Subject: *misc --- Assets/Scripts/Avatar/Trigger.cs | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Assets/Scripts/Avatar/Trigger.cs (limited to 'Assets/Scripts/Avatar/Trigger.cs') diff --git a/Assets/Scripts/Avatar/Trigger.cs b/Assets/Scripts/Avatar/Trigger.cs new file mode 100644 index 00000000..70a6d0f4 --- /dev/null +++ b/Assets/Scripts/Avatar/Trigger.cs @@ -0,0 +1,72 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public enum TriggerOnlyOnce +{ + Off = 0, + On = 1, +} + +public enum TriggerSwallow +{ + Off = 0, + On = 1 +} + + +/// +/// 不同效果的trigger继承这个基类 +/// + +public sealed class Trigger +{ + private TriggerSwallow m_Swallow; + public bool Swallow + { + get + { + return m_Swallow == TriggerSwallow.On; + } + } + + private ConditionBase m_Condition; + private List m_ActionChain = new List(); + + public Trigger(ConditionBase condition, List actions, TriggerOnlyOnce onlyOnce = TriggerOnlyOnce.Off, TriggerSwallow swallow = TriggerSwallow.On) + { + 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_Condition = condition; + m_ActionChain.Add(action); + } + + //重置触发器的参数 + public void Reset() + { + + } + + /// + /// 如果触发执行了,返回true,否则返回false + /// + /// + public bool Update() + { + if (m_Condition.Evaluate()) + { + foreach(var action in m_ActionChain) + { + action.Execute(); + } + return true; + } + return false; + } + +} \ No newline at end of file -- cgit v1.1-26-g67d0