Sample03_GameObjectAsObservable.cs 739 B

1234567891011121314151617181920212223
  1. #if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
  2. using UnityEngine;
  3. using UniRx.Triggers; // for enable gameObject.EventAsObservbale()
  4. namespace UniRx.Examples
  5. {
  6. public class Sample03_GameObjectAsObservable : MonoBehaviour
  7. {
  8. void Start()
  9. {
  10. // All events can subscribe by ***AsObservable if enables UniRx.Triggers
  11. this.OnMouseDownAsObservable()
  12. .SelectMany(_ => this.gameObject.UpdateAsObservable())
  13. .TakeUntil(this.gameObject.OnMouseUpAsObservable())
  14. .Select(_ => Input.mousePosition)
  15. .RepeatUntilDestroy(this)
  16. .Subscribe(x => Debug.Log(x), ()=> Debug.Log("!!!" + "complete"));
  17. }
  18. }
  19. }
  20. #endif