public static async UniTask UpdateForSeconds(float sec, Action action, CancellationToken token = default) { await UniTaskAsyncEnumerable.EveryUpdate().TakeUntil(UniTask.Delay(TimeSpan.FromSeconds(sec))).ForEachAsync(_ => { action?.Invoke(); }, token); }
static async UniTask Main() { await foreach (var _ in UniTaskAsyncEnumerable.EveryUpdate()) { Console.WriteLine("Update"); } }
public static async UniTask UpdateWhile(Func <AsyncUnit, bool> whilePredicate, Action action, CancellationToken token = default) { await UniTaskAsyncEnumerable.EveryUpdate().TakeWhile(whilePredicate).ForEachAsync(_ => { action?.Invoke(); }, token); }
private async UniTaskVoid Start() { await UniTaskAsyncEnumerable .EveryUpdate() .ForEachAsync(_ => { // Every update. Debug.Log(Time.frameCount); }, this.GetCancellationTokenOnDestroy()); }
private void Start() { var targetToken = _target.GetCancellationTokenOnDestroy(); UniTaskAsyncEnumerable.EveryUpdate() // 対象がキャンセル状態になったら値が取得できるようになる .SkipUntilCanceled(targetToken) .ForEachAsync( _ => Debug.Log(Time.frameCount), this.GetCancellationTokenOnDestroy()); }
private void Start() { var token = this.GetCancellationTokenOnDestroy(); _screenCamera.Subscribe(_ => ForceCalculateResolution()).AddTo(token); #if UNITY_EDITOR UniTaskAsyncEnumerable.EveryUpdate().Subscribe(unit => CalculateResolution()).AddTo(token); #endif CalculateResolution(); }
private void Start() { // Publish()の返り値は // IConnectableUniTaskAsyncEnumerable<T> _connectableUniTaskAsyncEnumerable = UniTaskAsyncEnumerable .EveryUpdate().Publish(); // この時点ではまだ値は発行されない _connectableUniTaskAsyncEnumerable .ForEachAsync(_ => Debug.Log(Time.frameCount)); }
private void Start() { var myClass = new MyClass(); // 10フレームに1回、MyClass.Do()を呼びだす UniTaskAsyncEnumerable.EveryUpdate() .Select((_, i) => i) .Where(x => x % 10 == 0) .BindTo( myClass, (m, f) => m.Do(f), this.GetCancellationTokenOnDestroy()); }
private async UniTaskVoid Start() { var token = this.GetCancellationTokenOnDestroy(); // EveryUpdate()は毎フレームのタイミングで完了するUniTaskを返す await UniTaskAsyncEnumerable.EveryUpdate() .Select((_, x) => x) // 5回まで実行する .Take(5) // ForEachAsyncで待機する .ForEachAsync(_ => Debug.Log(Time.frameCount), token); Debug.Log("Done!"); }
private async UniTaskVoid Start() { var targetToken = _target.GetCancellationTokenOnDestroy(); await UniTaskAsyncEnumerable.EveryUpdate() // 対象がキャンセル状態になったら // UniTaskAsyncEnumerableが完了する .TakeUntilCanceled(targetToken) .ForEachAsync( _ => Debug.Log(Time.frameCount), this.GetCancellationTokenOnDestroy()); Debug.Log("UniTaskAsyncEnumerable is finished."); }
private void Start() { HideHelp(); var token = this.GetCancellationTokenOnDestroy(); _gameplayState.Where(_ => _activeLevel == 0).SubscribeAwait(ShowTutorial, token); _cancelHelpEvents.SubscribeToAny(() => { _elapsedTime = 0f; ShowHelpAsync(false, token).Forget(); }, token); UniTaskAsyncEnumerable.EveryUpdate() .Subscribe(_ => StandbyShowHelp(token)); }
private async UniTask _Start() { //CancellationTokenSource不准,对于实时生成的事件流比如update还比较好用, //对于用户交互触发的事件流,例如按钮点击,会有一个事件的延迟,就是在cancel之后,还能再响应一次! var cts = new CancellationTokenSource(); UniTaskAsyncEnumerable.EveryUpdate().Where(_ => Input.GetKey(KeyCode.A)).Subscribe(_ => { cts.Cancel(); }); this.GetAsyncUpdateTrigger().Buffer(60).ForEachAsync(_ => { Debug.Log($"{"one second"}"); }, cts.Token); Debug.Log($"end"); // Nonebehaviour.Reg(); // await UniTaskAsyncEnumerable_TEST(); await btn.OnClickAsAsyncEnumerable().ForEachAsync(_ => Debug.Log("click"), cts.Token); }
private async UniTaskVoid Start() { var token = this.GetCancellationTokenOnDestroy(); // EveryUpdate()は毎フレームのタイミングで完了するUniTaskを返す await UniTaskAsyncEnumerable.EveryUpdate() .Select((_, x) => x) // 5回まで実行する .Take(5) // ForEachAwaitWithCancellationAsyncは // CancellationTokenが与えられる .ForEachAwaitWithCancellationAsync(async(_, ct) => { Debug.Log("before await:" + Time.frameCount); await UniTask.DelayFrame(10, cancellationToken: ct); Debug.Log("after await:" + Time.frameCount); }, token); Debug.Log("Done!"); }
private async UniTaskVoid Start() { var token = this.GetCancellationTokenOnDestroy(); await UniTaskAsyncEnumerable.EveryUpdate() .Select((_, x) => x) .Take(5) // ForEachAsyncは同期的に次のMoveNextAsync()を呼びだす .ForEachAsync(_ => { // 完了を待機する必要がない非同期処理ならば // UniTask.Void が利用できる UniTask.Action(async() => { Debug.Log("before await:" + Time.frameCount); await UniTask.DelayFrame(10, cancellationToken: token); Debug.Log("after await:" + Time.frameCount); }); }, token); Debug.Log("Done!"); }
public PrismClient(AppSettings settings) { this.Client = new PrismLoadBalancingClient(settings); this.thread = new PrismThread(this.Client); #if false //UniTask.Run UniTaskAsyncEnumerable.EveryUpdate(PlayerLoopTiming.PreUpdate).ForEachAsync(_ => { this.Client.DispatchIncomingCommands(); }, cts.Token).Forget(Debug.LogException); UniTaskAsyncEnumerable.EveryUpdate(PlayerLoopTiming.LastPostLateUpdate).ForEachAsync(_ => { var peer = this.Client.LoadBalancingPeer; var lastSendTime = Math.Max(peer.LastSendOutgoingTime, peer.LastSendAckTime); if (peer.ConnectionTime - lastSendTime >= 50) { this.Client.SendOutgoingCommands(); } }, cts.Token).Forget(Debug.LogException); #endif // TODO: // Application.focusChanged += application_focusChanged; }
public static void Reg() { UniTaskAsyncEnumerable.EveryUpdate().ForEachAsync(_ => { Debug.Log($"update(){Time.frameCount}"); }); }