GenericEvents.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace KairoEngine.Core
  5. {
  6. public class GenericEvents
  7. {
  8. #region Empty_Event
  9. public static Dictionary<string, System.Action> list = new Dictionary<string, System.Action>();
  10. public static void StartListening(string title, System.Action listener)
  11. {
  12. System.Action action = null;
  13. if (list.TryGetValue(title, out action))
  14. {
  15. action += listener;
  16. list[title] = action;
  17. }
  18. else
  19. {
  20. action += listener;
  21. list.Add(title, action);
  22. }
  23. }
  24. public static void StopListening(string title, System.Action listener)
  25. {
  26. System.Action action = null;
  27. if (list.TryGetValue(title, out action))
  28. {
  29. action -= listener;
  30. list[title] = action;
  31. }
  32. }
  33. public static void Trigger(string title)
  34. {
  35. System.Action action = null;
  36. if (list.TryGetValue(title, out action))
  37. {
  38. if(action != null) action();
  39. }
  40. }
  41. #endregion
  42. #region String_Event
  43. public static Dictionary<string, System.Action<string>> listString = new Dictionary<string, System.Action<string>>();
  44. public static void StartListening(string title, System.Action<string> listener)
  45. {
  46. System.Action<string> action = null;
  47. if (listString.TryGetValue(title, out action))
  48. {
  49. action += listener;
  50. listString[title] = action;
  51. }
  52. else
  53. {
  54. action += listener;
  55. listString.Add(title, action);
  56. }
  57. }
  58. public static void StopListening(string title, System.Action<string> listener)
  59. {
  60. System.Action<string> action = null;
  61. if (listString.TryGetValue(title, out action))
  62. {
  63. action -= listener;
  64. listString[title] = action;
  65. }
  66. }
  67. public static void Trigger(string title, string text)
  68. {
  69. System.Action<string> action = null;
  70. if (listString.TryGetValue(title, out action))
  71. {
  72. if(action != null) action(text);
  73. }
  74. }
  75. #endregion
  76. #region Float_Event
  77. public static Dictionary<string, System.Action<float>> list2 = new Dictionary<string, System.Action<float>>();
  78. public static void StartListening(string title, System.Action<float> listener)
  79. {
  80. System.Action<float> action = null;
  81. if (list2.TryGetValue(title, out action))
  82. {
  83. action += listener;
  84. list2[title] = action;
  85. }
  86. else
  87. {
  88. action += listener;
  89. list2.Add(title, action);
  90. }
  91. }
  92. public static void StopListening(string title, System.Action<float> listener)
  93. {
  94. System.Action<float> action = null;
  95. if (list2.TryGetValue(title, out action))
  96. {
  97. action -= listener;
  98. list2[title] = action;
  99. }
  100. }
  101. public static void Trigger(string title, float value)
  102. {
  103. System.Action<float> action = null;
  104. if (list2.TryGetValue(title, out action))
  105. {
  106. if(action != null) action(value);
  107. }
  108. }
  109. #endregion
  110. #region Float_Float_Event
  111. public static Dictionary<string, System.Action<float, float>> list3 = new Dictionary<string, System.Action<float, float>>();
  112. public static void StartListening(string title, System.Action<float, float> listener)
  113. {
  114. System.Action<float, float> action = null;
  115. if (list3.TryGetValue(title, out action))
  116. {
  117. action += listener;
  118. list3[title] = action;
  119. }
  120. else
  121. {
  122. action += listener;
  123. list3.Add(title, action);
  124. }
  125. }
  126. public static void StopListening(string title, System.Action<float, float> listener)
  127. {
  128. System.Action<float, float> action = null;
  129. if (list3.TryGetValue(title, out action))
  130. {
  131. action -= listener;
  132. list3[title] = action;
  133. }
  134. }
  135. public static void Trigger(string title, float value1, float value2)
  136. {
  137. System.Action<float, float> action = null;
  138. if (list3.TryGetValue(title, out action))
  139. {
  140. if(action != null) action(value1, value2);
  141. }
  142. }
  143. #endregion
  144. #region Int_Event
  145. public static Dictionary<string, System.Action<int>> list4 = new Dictionary<string, System.Action<int>>();
  146. public static void StartListening(string title, System.Action<int> listener)
  147. {
  148. System.Action<int> action = null;
  149. if (list4.TryGetValue(title, out action))
  150. {
  151. action += listener;
  152. list4[title] = action;
  153. }
  154. else
  155. {
  156. action += listener;
  157. list4.Add(title, action);
  158. }
  159. }
  160. public static void StopListening(string title, System.Action<int> listener)
  161. {
  162. System.Action<int> action = null;
  163. if (list4.TryGetValue(title, out action))
  164. {
  165. action -= listener;
  166. list4[title] = action;
  167. }
  168. }
  169. public static void Trigger(string title, int value)
  170. {
  171. System.Action<int> action = null;
  172. if (list4.TryGetValue(title, out action))
  173. {
  174. if(action != null) action(value);
  175. }
  176. }
  177. #endregion
  178. #region String_Int_Event
  179. public static Dictionary<string, System.Action<string, int>> list5 = new Dictionary<string, System.Action<string, int>>();
  180. public static void StartListening(string title, System.Action<string, int> listener)
  181. {
  182. System.Action<string, int> action = null;
  183. if (list5.TryGetValue(title, out action))
  184. {
  185. action += listener;
  186. list5[title] = action;
  187. }
  188. else
  189. {
  190. action += listener;
  191. list5.Add(title, action);
  192. }
  193. }
  194. public static void StopListening(string title, System.Action<string, int> listener)
  195. {
  196. System.Action<string, int> action = null;
  197. if (list5.TryGetValue(title, out action))
  198. {
  199. action -= listener;
  200. list5[title] = action;
  201. }
  202. }
  203. public static void Trigger(string title, string text, int value)
  204. {
  205. System.Action<string, int> action = null;
  206. if (list5.TryGetValue(title, out action))
  207. {
  208. if(action != null) action(text, value);
  209. }
  210. }
  211. #endregion
  212. #region String_float_Event
  213. public static Dictionary<string, System.Action<string, float>> stringFloatList = new Dictionary<string, System.Action<string, float>>();
  214. public static void StartListening(string title, System.Action<string, float> listener)
  215. {
  216. System.Action<string, float> action = null;
  217. if (stringFloatList.TryGetValue(title, out action))
  218. {
  219. action += listener;
  220. stringFloatList[title] = action;
  221. }
  222. else
  223. {
  224. action += listener;
  225. stringFloatList.Add(title, action);
  226. }
  227. }
  228. public static void StopListening(string title, System.Action<string, float> listener)
  229. {
  230. System.Action<string, float> action = null;
  231. if (stringFloatList.TryGetValue(title, out action))
  232. {
  233. action -= listener;
  234. stringFloatList[title] = action;
  235. }
  236. }
  237. public static void Trigger(string title, string text, float value)
  238. {
  239. System.Action<string, float> action = null;
  240. if (stringFloatList.TryGetValue(title, out action))
  241. {
  242. if(action != null) action(text, value);
  243. }
  244. }
  245. #endregion
  246. #region String_string_Event
  247. public static Dictionary<string, System.Action<string, string>> stringStringList = new Dictionary<string, System.Action<string, string>>();
  248. public static void StartListening(string title, System.Action<string, string> listener)
  249. {
  250. System.Action<string, string> action = null;
  251. if (stringStringList.TryGetValue(title, out action))
  252. {
  253. action += listener;
  254. stringStringList[title] = action;
  255. }
  256. else
  257. {
  258. action += listener;
  259. stringStringList.Add(title, action);
  260. }
  261. }
  262. public static void StopListening(string title, System.Action<string, string> listener)
  263. {
  264. System.Action<string, string> action = null;
  265. if (stringStringList.TryGetValue(title, out action))
  266. {
  267. action -= listener;
  268. stringStringList[title] = action;
  269. }
  270. }
  271. public static void Trigger(string title, string text, string value)
  272. {
  273. System.Action<string, string> action = null;
  274. if (stringStringList.TryGetValue(title, out action))
  275. {
  276. if(action != null) action(text, value);
  277. }
  278. }
  279. #endregion
  280. #region ScriptableObject_Event
  281. public static Dictionary<string, System.Action<ScriptableObject>> list6 = new Dictionary<string, System.Action<ScriptableObject>>();
  282. public static void StartListening(string title, System.Action<ScriptableObject> listener)
  283. {
  284. System.Action<ScriptableObject> action = null;
  285. if (list6.TryGetValue(title, out action))
  286. {
  287. action += listener;
  288. list6[title] = action;
  289. }
  290. else
  291. {
  292. action += listener;
  293. list6.Add(title, action);
  294. }
  295. }
  296. public static void StopListening(string title, System.Action<ScriptableObject> listener)
  297. {
  298. System.Action<ScriptableObject> action = null;
  299. if (list6.TryGetValue(title, out action))
  300. {
  301. action -= listener;
  302. list6[title] = action;
  303. }
  304. }
  305. public static void Trigger(string title, ScriptableObject scriptableObject)
  306. {
  307. System.Action<ScriptableObject> action = null;
  308. if (list6.TryGetValue(title, out action))
  309. {
  310. if(action != null) action(scriptableObject);
  311. }
  312. }
  313. #endregion
  314. #region String_Vector3_Event
  315. public static Dictionary<string, System.Action<string, Vector3>> listStringVector3 = new Dictionary<string, System.Action<string, Vector3>>();
  316. public static void StartListening(string title, System.Action<string, Vector3> listener)
  317. {
  318. System.Action<string, Vector3> action = null;
  319. if (listStringVector3.TryGetValue(title, out action))
  320. {
  321. action += listener;
  322. listStringVector3[title] = action;
  323. }
  324. else
  325. {
  326. action += listener;
  327. listStringVector3.Add(title, action);
  328. }
  329. }
  330. public static void StopListening(string title, System.Action<string, Vector3> listener)
  331. {
  332. System.Action<string, Vector3> action = null;
  333. if (listStringVector3.TryGetValue(title, out action))
  334. {
  335. action -= listener;
  336. listStringVector3[title] = action;
  337. }
  338. }
  339. public static void Trigger(string title, string text, Vector3 value)
  340. {
  341. System.Action<string, Vector3> action = null;
  342. if (listStringVector3.TryGetValue(title, out action))
  343. {
  344. if(action != null) action(text, value);
  345. }
  346. }
  347. #endregion
  348. }
  349. }