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 String_float_Event public static Dictionary> stringFloatList = new Dictionary>(); public static void StartListeningForStringFloat(string title, System.Action listener) => StartListening(title, listener); public static void StartListening(string title, System.Action listener) { System.Action action = null; if (stringFloatList.TryGetValue(title, out action)) { action += listener; stringFloatList[title] = action; } else { action += listener; stringFloatList.Add(title, action); } } public static void StopListeningForStringFloat(string title, System.Action listener) => StopListening(title, listener); public static void StopListening(string title, System.Action listener) { System.Action action = null; if (stringFloatList.TryGetValue(title, out action)) { action -= listener; stringFloatList[title] = action; } } public static void Trigger(string title, string text, float value) { System.Action action = null; if (stringFloatList.TryGetValue(title, out action)) { if(action != null) action(text, value); } } #endregion #region String_string_Event public static Dictionary> stringStringList = new Dictionary>(); public static void StartListening(string title, System.Action listener) { System.Action action = null; if (stringStringList.TryGetValue(title, out action)) { action += listener; stringStringList[title] = action; } else { action += listener; stringStringList.Add(title, action); } } public static void StopListening(string title, System.Action listener) { System.Action action = null; if (stringStringList.TryGetValue(title, out action)) { action -= listener; stringStringList[title] = action; } } public static void Trigger(string title, string text, string value) { System.Action action = null; if (stringStringList.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 } }