GenericEventsStoryExtensions.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace KairoEngine.Core
  5. {
  6. public static class GenericEventsStoryExtensions
  7. {
  8. public static Dictionary<string, System.Action<StoryStepData>> list = new Dictionary<string, System.Action<StoryStepData>>();
  9. public static void StartListening(this GenericEvents e, string title, System.Action<StoryStepData> listener)
  10. {
  11. System.Action<StoryStepData> action = null;
  12. if (list.TryGetValue(title, out action))
  13. {
  14. action += listener;
  15. list[title] = action;
  16. }
  17. else
  18. {
  19. action += listener;
  20. list.Add(title, action);
  21. }
  22. }
  23. public static void StopListening(this GenericEvents e,string title, System.Action<StoryStepData> listener)
  24. {
  25. System.Action<StoryStepData> action = null;
  26. if (list.TryGetValue(title, out action))
  27. {
  28. action -= listener;
  29. list[title] = action;
  30. }
  31. }
  32. public static void Trigger(this GenericEvents e, string title, StoryStepData storyStepData)
  33. {
  34. System.Action<StoryStepData> action = null;
  35. if (list.TryGetValue(title, out action))
  36. {
  37. if(action != null) action(storyStepData);
  38. }
  39. }
  40. }
  41. }