1
0

ObservableCanvasGroupChangedTrigger.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // after uGUI(from 4.6)
  2. #if !(UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
  3. using System;
  4. using UnityEngine;
  5. namespace UniRx.Triggers
  6. {
  7. [DisallowMultipleComponent]
  8. public class ObservableCanvasGroupChangedTrigger : ObservableTriggerBase
  9. {
  10. Subject<Unit> onCanvasGroupChanged;
  11. // Callback that is sent if the canvas group is changed
  12. void OnCanvasGroupChanged()
  13. {
  14. if (onCanvasGroupChanged != null) onCanvasGroupChanged.OnNext(Unit.Default);
  15. }
  16. /// <summary>Callback that is sent if the canvas group is changed.</summary>
  17. public IObservable<Unit> OnCanvasGroupChangedAsObservable()
  18. {
  19. return onCanvasGroupChanged ?? (onCanvasGroupChanged = new Subject<Unit>());
  20. }
  21. protected override void RaiseOnCompletedOnDestroy()
  22. {
  23. if (onCanvasGroupChanged != null)
  24. {
  25. onCanvasGroupChanged.OnCompleted();
  26. }
  27. }
  28. }
  29. }
  30. #endif