diff options
Diffstat (limited to 'Assets/Scripts/Avatar/Trigger.cs')
-rw-r--r-- | Assets/Scripts/Avatar/Trigger.cs | 72 |
1 files changed, 72 insertions, 0 deletions
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 +} + + +/// <summary> +/// 不同效果的trigger继承这个基类 +/// </summary> + +public sealed class Trigger +{ + private TriggerSwallow m_Swallow; + public bool Swallow + { + get + { + return m_Swallow == TriggerSwallow.On; + } + } + + private ConditionBase m_Condition; + private List<ActionBase> m_ActionChain = new List<ActionBase>(); + + public Trigger(ConditionBase condition, List<ActionBase> 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() + { + + } + + /// <summary> + /// 如果触发执行了,返回true,否则返回false + /// </summary> + /// <returns></returns> + 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 |