GenericEventsCharacterExtensions.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using KairoEngine.Core;
  5. namespace KairoEngine.CharacterSystem
  6. {
  7. public static class GenericEventsCharacterExtensions
  8. {
  9. public static Dictionary<string, System.Action<CharacterController>> list = new Dictionary<string, System.Action<CharacterController>>();
  10. public static void StartListening(this GenericEvents e, string title, System.Action<CharacterController> listener)
  11. {
  12. System.Action<CharacterController> 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(this GenericEvents e,string title, System.Action<CharacterController> listener)
  25. {
  26. System.Action<CharacterController> action = null;
  27. if (list.TryGetValue(title, out action))
  28. {
  29. action -= listener;
  30. list[title] = action;
  31. }
  32. }
  33. public static void Trigger(this GenericEvents e, string title, CharacterController value)
  34. {
  35. System.Action<CharacterController> action = null;
  36. if (list.TryGetValue(title, out action))
  37. {
  38. if(action != null) action(value);
  39. }
  40. }
  41. }
  42. }