From 3f302e8294db8cee3f5206b751fe48d0e31f4a26 Mon Sep 17 00:00:00 2001 From: uurha Date: Sat, 17 Aug 2024 22:54:01 +0000 Subject: [PATCH] Merge pull request #45 from techno-dwarf-works/feature/refactoring Version 0.0.42 --- Runtime/Utility/TaskUtility.cs | 19 +++++++++++++++++-- package.json | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Runtime/Utility/TaskUtility.cs b/Runtime/Utility/TaskUtility.cs index 5f5e620..c110f55 100644 --- a/Runtime/Utility/TaskUtility.cs +++ b/Runtime/Utility/TaskUtility.cs @@ -1,18 +1,33 @@ using System; using System.Threading; using System.Threading.Tasks; +using UnityEngine; namespace Better.Commons.Runtime.Utility { public static class TaskUtility { - public static Task WaitForSeconds(float seconds, CancellationToken cancellationToken = default) + public static async Task WaitForSeconds(float seconds, CancellationToken cancellationToken = default) + { + if (seconds <= 0 || cancellationToken.IsCancellationRequested) + { + return; + } + + while (seconds > 0 && !cancellationToken.IsCancellationRequested) + { + await Task.Yield(); + seconds -= Time.unscaledDeltaTime; + } + } + + public static Task Delay(float seconds, CancellationToken cancellationToken = default) { if (seconds <= 0 || cancellationToken.IsCancellationRequested) { return Task.CompletedTask; } - + var millisecondsDelay = TimeUtility.SecondsToMilliseconds(seconds); return Task.Delay(millisecondsDelay, cancellationToken); } diff --git a/package.json b/package.json index bc4cbb4..bbf929d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.tdw.better.commons", "displayName": "Better Commons", - "version": "0.0.41", + "version": "0.0.42", "unity": "2021.3", "description": " ", "dependencies": {