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