diff options
author | chai <215380520@qq.com> | 2023-05-15 09:28:11 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-05-15 09:28:11 +0800 |
commit | 3b036c6de871aa519a1f7fbfb52e09618945041f (patch) | |
tree | d5dc6d4f1d501e4ce3c6d69ca7a698a03634490c /WorldlineKeepers/Assets/Scripts/Tools/TriggerSystem | |
parent | 6fb204d494b897907d655b5752196983a82ceba2 (diff) |
*misc
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts/Tools/TriggerSystem')
4 files changed, 151 insertions, 0 deletions
diff --git a/WorldlineKeepers/Assets/Scripts/Tools/TriggerSystem/ActiveTrigger.cs b/WorldlineKeepers/Assets/Scripts/Tools/TriggerSystem/ActiveTrigger.cs new file mode 100644 index 0000000..1a4e988 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/TriggerSystem/ActiveTrigger.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json.Serialization; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK +{ + + /// <summary> + /// 定期轮训条件的主动式触发器。不安全 + /// </summary> + public class ActiveTrigger + { + + + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Tools/TriggerSystem/ActiveTrigger.cs.meta b/WorldlineKeepers/Assets/Scripts/Tools/TriggerSystem/ActiveTrigger.cs.meta new file mode 100644 index 0000000..1fa37dc --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/TriggerSystem/ActiveTrigger.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6e06c17e867b36f4bb0b6796ed74b89b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/WorldlineKeepers/Assets/Scripts/Tools/TriggerSystem/Trigger.cs b/WorldlineKeepers/Assets/Scripts/Tools/TriggerSystem/Trigger.cs new file mode 100644 index 0000000..ed69284 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/TriggerSystem/Trigger.cs @@ -0,0 +1,110 @@ +using System.Collections.Generic; +using System.Diagnostics.Tracing; + +namespace WK +{ + + /// <summary> + /// 事件发生后检测条件的被动触发器 + /// </summary> + public class Trigger + { + public class ConditionBase + { + public virtual bool Evaluate(params object[] args) { return false; } + + public static ConditionBase Always = new ConditionAlways(); + public static ConditionBase AlwaysNot = new ConditionAlwaysNot(); + } + + public class ConditionAlways : ConditionBase + { + public override bool Evaluate(params object[] args) + { + return true; + } + } + + public class ConditionAlwaysNot : ConditionBase + { + public override bool Evaluate(params object[] args) + { + return false; + } + } + + public class ConditionAnd : ConditionBase + { + private ConditionBase m_Left; + private ConditionBase m_Right; + public ConditionAnd(ConditionBase left, ConditionBase right) + { + m_Left = left; + m_Right = right; + } + public override bool Evaluate(params object[] args) + { + return m_Left.Evaluate(args) && m_Right.Evaluate(args); + } + } + + public class ConditionOr : ConditionBase + { + private ConditionBase m_Left; + private ConditionBase m_Right; + public ConditionOr(ConditionBase left, ConditionBase right) + { + m_Left = left; + m_Right = right; + } + public override bool Evaluate(params object[] args) + { + return m_Left.Evaluate(args) || m_Right.Evaluate(args); + } + } + + public delegate void Action(params object[] args); + + // 触发事件 + private string m_Event; + // 触发条件 + private ConditionBase m_Condition; + // 触发操作 + private List<Action> m_Actions = new List<Action>(); + + public void SetEvent(string eventType) + { + if (m_Event != string.Empty || m_Event != null) + { + GlobalEventManager.Instance.UnRegister(m_Event, OnEvent); + } + m_Event = eventType; + GlobalEventManager.Instance.Register(eventType, OnEvent); + } + + public void AddAction(Action action) + { + m_Actions.Add(action); + } + + public void SetCondition(ConditionBase condition) + { + m_Condition = condition; + } + + public void OnEvent(params object[] args) + { + if (m_Condition == null) + return; + if (m_Condition.Evaluate()) + { + foreach (Action action in m_Actions) + { + action.Invoke(args); + } + } + } + + } + +} diff --git a/WorldlineKeepers/Assets/Scripts/Tools/TriggerSystem/Trigger.cs.meta b/WorldlineKeepers/Assets/Scripts/Tools/TriggerSystem/Trigger.cs.meta new file mode 100644 index 0000000..c5f1c19 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/TriggerSystem/Trigger.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c3ee81c4dceea3346b4c5e7b1d371e92 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |