UnityGraphicExtensions.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // for 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.Events;
  5. using UnityEngine.UI;
  6. namespace UniRx
  7. {
  8. public static partial class UnityGraphicExtensions
  9. {
  10. public static IObservable<Unit> DirtyLayoutCallbackAsObservable(this Graphic graphic)
  11. {
  12. return Observable.Create<Unit>(observer =>
  13. {
  14. UnityAction registerHandler = () => observer.OnNext(Unit.Default);
  15. graphic.RegisterDirtyLayoutCallback(registerHandler);
  16. return Disposable.Create(() => graphic.UnregisterDirtyLayoutCallback(registerHandler));
  17. });
  18. }
  19. public static IObservable<Unit> DirtyMaterialCallbackAsObservable(this Graphic graphic)
  20. {
  21. return Observable.Create<Unit>(observer =>
  22. {
  23. UnityAction registerHandler = () => observer.OnNext(Unit.Default);
  24. graphic.RegisterDirtyMaterialCallback(registerHandler);
  25. return Disposable.Create(() => graphic.UnregisterDirtyMaterialCallback(registerHandler));
  26. });
  27. }
  28. public static IObservable<Unit> DirtyVerticesCallbackAsObservable(this Graphic graphic)
  29. {
  30. return Observable.Create<Unit>(observer =>
  31. {
  32. UnityAction registerHandler = () => observer.OnNext(Unit.Default);
  33. graphic.RegisterDirtyVerticesCallback(registerHandler);
  34. return Disposable.Create(() => graphic.UnregisterDirtyVerticesCallback(registerHandler));
  35. });
  36. }
  37. }
  38. }
  39. #endif