ObservableUpdateTrigger.cs 853 B

12345678910111213141516171819202122232425262728293031
  1. using System; // require keep for Windows Universal App
  2. using UnityEngine;
  3. namespace UniRx.Triggers
  4. {
  5. [DisallowMultipleComponent]
  6. public class ObservableUpdateTrigger : ObservableTriggerBase
  7. {
  8. Subject<Unit> update;
  9. /// <summary>Update is called every frame, if the MonoBehaviour is enabled.</summary>
  10. void Update()
  11. {
  12. if (update != null) update.OnNext(Unit.Default);
  13. }
  14. /// <summary>Update is called every frame, if the MonoBehaviour is enabled.</summary>
  15. public IObservable<Unit> UpdateAsObservable()
  16. {
  17. return update ?? (update = new Subject<Unit>());
  18. }
  19. protected override void RaiseOnCompletedOnDestroy()
  20. {
  21. if (update != null)
  22. {
  23. update.OnCompleted();
  24. }
  25. }
  26. }
  27. }