ObservableFixedUpdateTrigger.cs 949 B

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