quantum-space-buddies/QSB/Utility/Delay.cs

29 lines
576 B
C#
Raw Normal View History

2022-01-29 09:23:29 +00:00
using Cysharp.Threading.Tasks;
using System;
2022-03-03 03:46:33 +00:00
namespace QSB.Utility;
public static class Delay
2022-01-29 09:23:29 +00:00
{
2022-03-03 03:46:33 +00:00
public static void RunNextFrame(Action action) => UniTask.Create(async () =>
{
2022-03-03 03:46:33 +00:00
await UniTask.WaitForEndOfFrame();
action();
});
2022-03-03 03:46:33 +00:00
public static void RunFramesLater(int n, Action action) => UniTask.Create(async () =>
{
for (var i = 0; i < n; i++)
{
2022-03-03 03:46:33 +00:00
await UniTask.WaitForEndOfFrame();
}
2022-01-29 09:31:05 +00:00
2022-03-03 03:46:33 +00:00
action();
});
2022-03-03 03:46:33 +00:00
public static void RunWhen(Func<bool> predicate, Action action) => UniTask.Create(async () =>
{
await UniTask.WaitUntil(predicate);
action();
});
}