Sample08_DetectDoubleClick.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using UnityEngine;
  7. namespace UniRx.Examples
  8. {
  9. public class Sample08_DetectDoubleClick : MonoBehaviour
  10. {
  11. void Start()
  12. {
  13. // Global event handling is very useful.
  14. // UniRx can handle there events.
  15. // Observable.EveryUpdate/EveryFixedUpdate/EveryEndOfFrame
  16. // Observable.EveryApplicationFocus/EveryApplicationPause
  17. // Observable.OnceApplicationQuit
  18. // This DoubleCLick Sample is from
  19. // The introduction to Reactive Programming you've been missing
  20. // https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
  21. var clickStream = Observable.EveryUpdate()
  22. .Where(_ => Input.GetMouseButtonDown(0));
  23. clickStream.Buffer(clickStream.Throttle(TimeSpan.FromMilliseconds(250)))
  24. .Where(xs => xs.Count >= 2)
  25. .Subscribe(xs => Debug.Log("DoubleClick Detected! Count:" + xs.Count));
  26. }
  27. }
  28. }