summaryrefslogtreecommitdiff
path: root/YesCommander/Assets/Scripts/Tools/TriggerSystem
diff options
context:
space:
mode:
Diffstat (limited to 'YesCommander/Assets/Scripts/Tools/TriggerSystem')
-rw-r--r--YesCommander/Assets/Scripts/Tools/TriggerSystem/Action.cs16
-rw-r--r--YesCommander/Assets/Scripts/Tools/TriggerSystem/Action.cs.meta11
-rw-r--r--YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalActiveTrigger.cs18
-rw-r--r--YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalActiveTrigger.cs.meta11
-rw-r--r--YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalPassiveTrigger.cs110
-rw-r--r--YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalPassiveTrigger.cs.meta11
-rw-r--r--YesCommander/Assets/Scripts/Tools/TriggerSystem/Trigger.cs44
-rw-r--r--YesCommander/Assets/Scripts/Tools/TriggerSystem/Trigger.cs.meta11
8 files changed, 232 insertions, 0 deletions
diff --git a/YesCommander/Assets/Scripts/Tools/TriggerSystem/Action.cs b/YesCommander/Assets/Scripts/Tools/TriggerSystem/Action.cs
new file mode 100644
index 0000000..ad304b1
--- /dev/null
+++ b/YesCommander/Assets/Scripts/Tools/TriggerSystem/Action.cs
@@ -0,0 +1,16 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace YC
+{
+
+ public abstract class Action
+ {
+ public abstract void Execute(params object[] args);
+
+ public virtual void Init() { }
+
+ }
+
+}
diff --git a/YesCommander/Assets/Scripts/Tools/TriggerSystem/Action.cs.meta b/YesCommander/Assets/Scripts/Tools/TriggerSystem/Action.cs.meta
new file mode 100644
index 0000000..124d597
--- /dev/null
+++ b/YesCommander/Assets/Scripts/Tools/TriggerSystem/Action.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: ce0de120c2520f84492089c52286f7cd
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalActiveTrigger.cs b/YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalActiveTrigger.cs
new file mode 100644
index 0000000..4933660
--- /dev/null
+++ b/YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalActiveTrigger.cs
@@ -0,0 +1,18 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace YC
+{
+
+ /// <summary>
+ /// 定期轮训条件的主动式触发器。不安全
+ /// </summary>
+ public class GlobalActiveTrigger
+ {
+
+
+
+ }
+
+}
diff --git a/YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalActiveTrigger.cs.meta b/YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalActiveTrigger.cs.meta
new file mode 100644
index 0000000..1fa37dc
--- /dev/null
+++ b/YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalActiveTrigger.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/YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalPassiveTrigger.cs b/YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalPassiveTrigger.cs
new file mode 100644
index 0000000..2ef3063
--- /dev/null
+++ b/YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalPassiveTrigger.cs
@@ -0,0 +1,110 @@
+using System.Collections.Generic;
+using System.Diagnostics.Tracing;
+
+namespace YC
+{
+
+ /// <summary>
+ /// 事件发生后检测条件的被动触发器
+ /// </summary>
+ public class GlobalPassiveTrigger
+ {
+ 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/YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalPassiveTrigger.cs.meta b/YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalPassiveTrigger.cs.meta
new file mode 100644
index 0000000..c5f1c19
--- /dev/null
+++ b/YesCommander/Assets/Scripts/Tools/TriggerSystem/GlobalPassiveTrigger.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: c3ee81c4dceea3346b4c5e7b1d371e92
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/YesCommander/Assets/Scripts/Tools/TriggerSystem/Trigger.cs b/YesCommander/Assets/Scripts/Tools/TriggerSystem/Trigger.cs
new file mode 100644
index 0000000..ab03971
--- /dev/null
+++ b/YesCommander/Assets/Scripts/Tools/TriggerSystem/Trigger.cs
@@ -0,0 +1,44 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace YC
+{
+
+ /// <summary>
+ /// 保存action并由OnActive()指定触发时机和条件
+ /// </summary>
+ public abstract class Trigger
+ {
+ public delegate void TriggerHandler(params object[] args);
+
+ public event TriggerHandler handler;
+
+ //需要指定调用FireTrigger的时机
+ public abstract void OnActive();
+
+ public virtual void OnDeactive()
+ {
+ }
+
+ protected void FireTrigger(params object[] args)
+ {
+ handler?.Invoke(args);
+ }
+
+ }
+ /*
+ public class OnPlayerHurt : Trigger
+ {
+ public override void OnActive()
+ {
+ UnitManager.Instance.player.AddObserver("Player.Hurt", OnPlayerHurtCallbak);
+ }
+
+ private void OnPlayerHurtCallbak()
+ {
+ FireTrigger();
+ }
+ }
+ */
+}
diff --git a/YesCommander/Assets/Scripts/Tools/TriggerSystem/Trigger.cs.meta b/YesCommander/Assets/Scripts/Tools/TriggerSystem/Trigger.cs.meta
new file mode 100644
index 0000000..08630d3
--- /dev/null
+++ b/YesCommander/Assets/Scripts/Tools/TriggerSystem/Trigger.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 93ca5bd37a4caea40ad66ea9d41f8530
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: