|
@@ -0,0 +1,322 @@
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+
|
|
|
+namespace KairoEngine.Core
|
|
|
+{
|
|
|
+ public class GenericEvents
|
|
|
+ {
|
|
|
+ #region Empty_Event
|
|
|
+
|
|
|
+ public static Dictionary<string, System.Action> list = new Dictionary<string, System.Action>();
|
|
|
+
|
|
|
+ public static void StartListening(string title, System.Action listener)
|
|
|
+ {
|
|
|
+ System.Action action = null;
|
|
|
+ if (list.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ list[title] = action;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ list.Add(title, action);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void StopListening(string title, System.Action listener)
|
|
|
+ {
|
|
|
+ System.Action action = null;
|
|
|
+ if (list.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action -= listener;
|
|
|
+ list[title] = action;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Trigger(string title)
|
|
|
+ {
|
|
|
+ System.Action action = null;
|
|
|
+ if (list.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ if(action != null) action();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region String_Event
|
|
|
+
|
|
|
+ public static Dictionary<string, System.Action<string>> listString = new Dictionary<string, System.Action<string>>();
|
|
|
+
|
|
|
+ public static void StartListening(string title, System.Action<string> listener)
|
|
|
+ {
|
|
|
+ System.Action<string> action = null;
|
|
|
+ if (listString.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ listString[title] = action;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ listString.Add(title, action);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void StopListening(string title, System.Action<string> listener)
|
|
|
+ {
|
|
|
+ System.Action<string> action = null;
|
|
|
+ if (listString.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action -= listener;
|
|
|
+ listString[title] = action;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Trigger(string title, string text)
|
|
|
+ {
|
|
|
+ System.Action<string> action = null;
|
|
|
+ if (listString.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ if(action != null) action(text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Float_Event
|
|
|
+
|
|
|
+ public static Dictionary<string, System.Action<float>> list2 = new Dictionary<string, System.Action<float>>();
|
|
|
+
|
|
|
+ public static void StartListening(string title, System.Action<float> listener)
|
|
|
+ {
|
|
|
+ System.Action<float> action = null;
|
|
|
+ if (list2.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ list2[title] = action;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ list2.Add(title, action);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void StopListening(string title, System.Action<float> listener)
|
|
|
+ {
|
|
|
+ System.Action<float> action = null;
|
|
|
+ if (list2.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action -= listener;
|
|
|
+ list2[title] = action;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Trigger(string title, float value)
|
|
|
+ {
|
|
|
+ System.Action<float> action = null;
|
|
|
+ if (list2.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ if(action != null) action(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Float_Float_Event
|
|
|
+
|
|
|
+ public static Dictionary<string, System.Action<float, float>> list3 = new Dictionary<string, System.Action<float, float>>();
|
|
|
+
|
|
|
+ public static void StartListening(string title, System.Action<float, float> listener)
|
|
|
+ {
|
|
|
+ System.Action<float, float> action = null;
|
|
|
+ if (list3.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ list3[title] = action;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ list3.Add(title, action);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void StopListening(string title, System.Action<float, float> listener)
|
|
|
+ {
|
|
|
+ System.Action<float, float> action = null;
|
|
|
+ if (list3.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action -= listener;
|
|
|
+ list3[title] = action;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Trigger(string title, float value1, float value2)
|
|
|
+ {
|
|
|
+ System.Action<float, float> action = null;
|
|
|
+ if (list3.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ if(action != null) action(value1, value2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Int_Event
|
|
|
+
|
|
|
+ public static Dictionary<string, System.Action<int>> list4 = new Dictionary<string, System.Action<int>>();
|
|
|
+
|
|
|
+ public static void StartListening(string title, System.Action<int> listener)
|
|
|
+ {
|
|
|
+ System.Action<int> action = null;
|
|
|
+ if (list4.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ list4[title] = action;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ list4.Add(title, action);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void StopListening(string title, System.Action<int> listener)
|
|
|
+ {
|
|
|
+ System.Action<int> action = null;
|
|
|
+ if (list4.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action -= listener;
|
|
|
+ list4[title] = action;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Trigger(string title, int value)
|
|
|
+ {
|
|
|
+ System.Action<int> action = null;
|
|
|
+ if (list4.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ if(action != null) action(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region String_Int_Event
|
|
|
+
|
|
|
+ public static Dictionary<string, System.Action<string, int>> list5 = new Dictionary<string, System.Action<string, int>>();
|
|
|
+
|
|
|
+ public static void StartListening(string title, System.Action<string, int> listener)
|
|
|
+ {
|
|
|
+ System.Action<string, int> action = null;
|
|
|
+ if (list5.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ list5[title] = action;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ list5.Add(title, action);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void StopListening(string title, System.Action<string, int> listener)
|
|
|
+ {
|
|
|
+ System.Action<string, int> action = null;
|
|
|
+ if (list5.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action -= listener;
|
|
|
+ list5[title] = action;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Trigger(string title, string text, int value)
|
|
|
+ {
|
|
|
+ System.Action<string, int> action = null;
|
|
|
+ if (list5.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ if(action != null) action(text, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region ScriptableObject_Event
|
|
|
+
|
|
|
+ public static Dictionary<string, System.Action<ScriptableObject>> list6 = new Dictionary<string, System.Action<ScriptableObject>>();
|
|
|
+
|
|
|
+ public static void StartListening(string title, System.Action<ScriptableObject> listener)
|
|
|
+ {
|
|
|
+ System.Action<ScriptableObject> action = null;
|
|
|
+ if (list6.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ list6[title] = action;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ list6.Add(title, action);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void StopListening(string title, System.Action<ScriptableObject> listener)
|
|
|
+ {
|
|
|
+ System.Action<ScriptableObject> action = null;
|
|
|
+ if (list6.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action -= listener;
|
|
|
+ list6[title] = action;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Trigger(string title, ScriptableObject scriptableObject)
|
|
|
+ {
|
|
|
+ System.Action<ScriptableObject> action = null;
|
|
|
+ if (list6.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ if(action != null) action(scriptableObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region String_Vector3_Event
|
|
|
+
|
|
|
+ public static Dictionary<string, System.Action<string, Vector3>> listStringVector3 = new Dictionary<string, System.Action<string, Vector3>>();
|
|
|
+
|
|
|
+ public static void StartListening(string title, System.Action<string, Vector3> listener)
|
|
|
+ {
|
|
|
+ System.Action<string, Vector3> action = null;
|
|
|
+ if (listStringVector3.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ listStringVector3[title] = action;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ action += listener;
|
|
|
+ listStringVector3.Add(title, action);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void StopListening(string title, System.Action<string, Vector3> listener)
|
|
|
+ {
|
|
|
+ System.Action<string, Vector3> action = null;
|
|
|
+ if (listStringVector3.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ action -= listener;
|
|
|
+ listStringVector3[title] = action;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Trigger(string title, string text, Vector3 value)
|
|
|
+ {
|
|
|
+ System.Action<string, Vector3> action = null;
|
|
|
+ if (listStringVector3.TryGetValue(title, out action))
|
|
|
+ {
|
|
|
+ if(action != null) action(text, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+}
|