diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs index 0cf8539..c8b6d10 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs @@ -93,6 +93,9 @@ namespace Cysharp.Threading.Tasks.Linq // return false instead of throw if (disposed || cancellationToken.IsCancellationRequested) return CompletedTasks.False; + // reset value here. + this.elapsed = 0; + completionSource.Reset(); return new UniTask(this, completionSource.Version); } @@ -121,7 +124,6 @@ namespace Cysharp.Threading.Tasks.Linq if (elapsed >= dueTime) { dueTimePhase = false; - elapsed = 0; completionSource.TrySetResult(true); } } @@ -135,7 +137,6 @@ namespace Cysharp.Threading.Tasks.Linq if (elapsed >= period) { - elapsed = 0; completionSource.TrySetResult(true); } } @@ -196,6 +197,10 @@ namespace Cysharp.Threading.Tasks.Linq // return false instead of throw if (disposed || cancellationToken.IsCancellationRequested) return CompletedTasks.False; + + // reset value here. + this.currentFrame = 0; + completionSource.Reset(); return new UniTask(this, completionSource.Version); } @@ -220,11 +225,10 @@ namespace Cysharp.Threading.Tasks.Linq if (dueTimePhase) { - if (currentFrame++ == dueTimeFrameCount) + if (currentFrame++ >= dueTimeFrameCount) { dueTimePhase = false; completionSource.TrySetResult(true); - currentFrame = 0; } } else @@ -235,10 +239,9 @@ namespace Cysharp.Threading.Tasks.Linq return false; } - if (++currentFrame == periodFrameCount) + if (++currentFrame >= periodFrameCount) { completionSource.TrySetResult(true); - currentFrame = 0; } } diff --git a/src/UniTask/Assets/Scenes/SandboxMain.cs b/src/UniTask/Assets/Scenes/SandboxMain.cs index ff96818..9b94c40 100644 --- a/src/UniTask/Assets/Scenes/SandboxMain.cs +++ b/src/UniTask/Assets/Scenes/SandboxMain.cs @@ -145,11 +145,13 @@ public class SandboxMain : MonoBehaviour //StartCoroutine(cor); + // UniTaskAsyncEnumerable.EveryUpdate(PlayerLoopTiming.FixedUpdate) - // await UniTask.Yield(PlayerLoopTiming.EarlyUpdate); + + await UniTask.Yield(PlayerLoopTiming.Update); Debug.Log("Start:" + Time.frameCount); - await UniTaskAsyncEnumerable.TimerFrame(3, 5, PlayerLoopTiming.LastPostLateUpdate).ForEachAsync(_ => + await UniTaskAsyncEnumerable.TimerFrame(3, 5, PlayerLoopTiming.Update).ForEachAsync(_ => { Debug.Log("Call:" + Time.frameCount); }, cancellationToken: this.GetCancellationTokenOnDestroy());