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.

43 lines
879B

  1. using System;
  2. namespace Svelto.Observer
  3. {
  4. public delegate void ObserverAction<DispatchType>(ref DispatchType parameter);
  5. public interface IObservable
  6. {
  7. event Action Notify;
  8. void Dispatch();
  9. }
  10. public interface IObservable<DispatchType>
  11. {
  12. event ObserverAction<DispatchType> Notify;
  13. void Dispatch(ref DispatchType parameter);
  14. }
  15. public class Observable<DispatchType>:IObservable<DispatchType>
  16. {
  17. public event ObserverAction<DispatchType> Notify;
  18. public void Dispatch(ref DispatchType parameter)
  19. {
  20. if (Notify != null)
  21. Notify(ref parameter);
  22. }
  23. }
  24. public class Observable:IObservable
  25. {
  26. public event Action Notify;
  27. public void Dispatch()
  28. {
  29. if (Notify != null)
  30. Notify();
  31. }
  32. }
  33. }