Example #1
0
 /// <summary>
 /// 按下之后开启一个定时器,定期触发,当松开之后删除这个定时器
 /// </summary>
 /// <param name="action"></param>
 void RegisterHoldPress(Action action)
 {
     btn.GetAsyncPointerDownTrigger()
     .Subscribe(
         async _ => {
         UniTaskAsyncEnumerable.Timer(TimeSpan.FromMilliseconds(3000), TimeSpan.FromMilliseconds(250))
         .TakeUntil(btn.GetAsyncPointerUpTrigger().FirstAsync()).Subscribe(o => { action.Invoke(); })
         .AddTo(this.GetCancellationTokenOnDestroy());
     }
         );
 }
Example #2
0
        public IEnumerator Timer() => UniTask.ToCoroutine(async() =>
        {
            await UniTask.Yield(PlayerLoopTiming.PreUpdate);

            {
                var initialSeconds = Time.realtimeSinceStartup;
                var xs             = await UniTaskAsyncEnumerable.Timer(TimeSpan.FromSeconds(2)).Select(_ => Time.realtimeSinceStartup).ToArrayAsync();

                Mathf.Approximately(initialSeconds, xs[0]).Should().BeFalse();
                Debug.Log("Init:" + initialSeconds);
                Debug.Log("After:" + xs[0]);
            }
        });
        private async UniTaskVoid Start()
        {
            await UniTaskAsyncEnumerable
            .Timer(TimeSpan.FromSeconds(1))
            .ForEachAsync(_ =>
            {
                // awaitしてから1秒後に実行される
                Debug.Log(Time.time);
            }, this.GetCancellationTokenOnDestroy());

            // ForEachAsyncがすべて終了したら到達
            Debug.Log("Done");
        }
Example #4
0
 private async UniTaskVoid Start()
 {
     // 無限長のUniTaskAsyncEnumerable
     await UniTaskAsyncEnumerable
     .Timer(
         dueTime : TimeSpan.FromSeconds(1),
         period : TimeSpan.FromSeconds(0.1))
     .ForEachAsync(_ =>
     {
         // 初回のみdueTime後
         // 2回目以降はperiod間隔
         Debug.Log(Time.time);
     }, this.GetCancellationTokenOnDestroy());
 }