123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- 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
- }
- }
|