2022-01-29 09:23:29 +00:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace QSB.Utility
|
|
|
|
|
{
|
2022-01-29 09:29:02 +00:00
|
|
|
|
public static class Delay
|
2022-01-29 09:23:29 +00:00
|
|
|
|
{
|
2022-01-29 09:25:40 +00:00
|
|
|
|
public static UniTask RunNextFrame(Action action) => UniTask.Create(async () =>
|
2022-01-29 09:23:29 +00:00
|
|
|
|
{
|
|
|
|
|
await UniTask.NextFrame();
|
|
|
|
|
action();
|
|
|
|
|
});
|
|
|
|
|
|
2022-01-29 09:27:00 +00:00
|
|
|
|
public static UniTask RunFramesLater(int n, Action action) => UniTask.Create(async () =>
|
2022-01-29 09:23:29 +00:00
|
|
|
|
{
|
|
|
|
|
await UniTask.DelayFrame(n);
|
|
|
|
|
action();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
public static UniTask RunWhen(Func<bool> predicate, Action action) => UniTask.Create(async () =>
|
|
|
|
|
{
|
|
|
|
|
await UniTask.WaitUntil(predicate);
|
|
|
|
|
action();
|
|
|
|
|
});
|
|
|
|
|
|
2022-01-29 09:25:40 +00:00
|
|
|
|
public static UniTask RunNextFrame(Func<UniTask> func) => UniTask.Create(async () =>
|
2022-01-29 09:23:29 +00:00
|
|
|
|
{
|
|
|
|
|
await UniTask.NextFrame();
|
|
|
|
|
await func();
|
|
|
|
|
});
|
|
|
|
|
|
2022-01-29 09:27:00 +00:00
|
|
|
|
public static UniTask RunFramesLater(int n, Func<UniTask> func) => UniTask.Create(async () =>
|
2022-01-29 09:23:29 +00:00
|
|
|
|
{
|
|
|
|
|
await UniTask.DelayFrame(n);
|
|
|
|
|
await func();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
public static UniTask RunWhen(Func<bool> predicate, Func<UniTask> func) => UniTask.Create(async () =>
|
|
|
|
|
{
|
|
|
|
|
await UniTask.WaitUntil(predicate);
|
|
|
|
|
await func();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|