Last active
October 17, 2015 15:27
-
-
Save TORISOUP/cd905bdd4d9d5fc95365 to your computer and use it in GitHub Desktop.
UniRxで長押しを取る版
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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