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
897B

  1. using System;
  2. namespace Svelto.ECS
  3. {
  4. public class DispatchOnSet<T>
  5. {
  6. public DispatchOnSet(EGID senderID)
  7. {
  8. _senderID = senderID;
  9. }
  10. public T value
  11. {
  12. set
  13. {
  14. _value = value;
  15. if (_paused == false)
  16. _subscribers(_senderID, value);
  17. }
  18. }
  19. public void NotifyOnValueSet(Action<EGID, T> action)
  20. {
  21. _subscribers += action;
  22. }
  23. public void StopNotify(Action<EGID, T> action)
  24. {
  25. _subscribers -= action;
  26. }
  27. public void PauseNotify() { _paused = true; }
  28. public void ResumeNotify() { _paused = false; }
  29. protected T _value;
  30. readonly EGID _senderID;
  31. Action<EGID, T> _subscribers;
  32. bool _paused;
  33. }
  34. }