Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2KB

  1. using System;
  2. public static class SafeEvent
  3. {
  4. public static void SafeRaise<T>(this Action<T> onEvent, T val)
  5. {
  6. if (onEvent != null)
  7. {
  8. var length = onEvent.GetInvocationList().Length;
  9. for (int index = 0; index < length; index++)
  10. {
  11. Action<T> handler = (Action<T>) onEvent.GetInvocationList()[index];
  12. try
  13. {
  14. if (handler != null) handler.Invoke(val);
  15. }
  16. catch (Exception e)
  17. {
  18. Utility.Console.LogException(e);
  19. }
  20. }
  21. }
  22. }
  23. public static void SafeRaise(this Action onEvent)
  24. {
  25. if (onEvent != null)
  26. {
  27. var length = onEvent.GetInvocationList().Length;
  28. for (int index = 0; index < length; index++)
  29. {
  30. Action handler = (Action)onEvent.GetInvocationList()[index];
  31. try
  32. {
  33. if (handler != null) handler.Invoke();
  34. }
  35. catch (Exception e)
  36. {
  37. Utility.Console.LogException(e);
  38. }
  39. }
  40. }
  41. }
  42. }