summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Avatar/Trigger.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Avatar/Trigger.cs')
-rw-r--r--Assets/Scripts/Avatar/Trigger.cs81
1 files changed, 0 insertions, 81 deletions
diff --git a/Assets/Scripts/Avatar/Trigger.cs b/Assets/Scripts/Avatar/Trigger.cs
deleted file mode 100644
index a885327c..00000000
--- a/Assets/Scripts/Avatar/Trigger.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-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>();
-
- private TriggerOnlyOnce m_OnlyOnce;
-
- private bool m_IsTriggered;
-
- public Trigger(ConditionBase condition, List<ActionBase> actions, TriggerOnlyOnce onlyOnce = TriggerOnlyOnce.Off, TriggerSwallow swallow = TriggerSwallow.On)
- {
- 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_OnlyOnce = onlyOnce;
- m_Swallow = swallow;
- m_Condition = condition;
- m_ActionChain.Add(action);
- }
-
- //重置触发器的参数
- public void Reset()
- {
- m_IsTriggered = false;
- }
-
- /// <summary>
- /// 如果触发执行了,返回true,否则返回false
- /// </summary>
- /// <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;
- }
-
-} \ No newline at end of file