1
0

ObservableLateUpdateTrigger.cs 893 B

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