Skip to content

Instantly share code, notes, and snippets.

@TORISOUP
Last active October 17, 2015 15:27
Show Gist options
  • Save TORISOUP/cd905bdd4d9d5fc95365 to your computer and use it in GitHub Desktop.
Save TORISOUP/cd905bdd4d9d5fc95365 to your computer and use it in GitHub Desktop.
UniRxで長押しを取る版
void Start()
{
var mouseDownStream = this.UpdateAsObservable().Where(_ => Input.GetMouseButtonDown(0));
var mouseUpStream = this.UpdateAsObservable().Where(_ => Input.GetMouseButtonUp(0));
//長押しの判定
//マウスクリックされたら3秒後にOnNextを流す
mouseDownStream
.SelectMany(_ => Observable.Timer(TimeSpan.FromSeconds(3)))
//途中でMouseUpされたらストリームをリセット
.TakeUntil(mouseUpStream)
.RepeatUntilDestroy(this.gameObject)
.Subscribe(_ => Debug.Log("長押し"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment