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-02-25 06:04:54 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
await UniTask.WaitForEndOfFrame();
|
|
|
|
|
action();
|
|
|
|
|
});
|
2022-01-29 10:03:31 +00:00
|
|
|
|
|
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-02-27 12:40:44 +00:00
|
|
|
|
{
|
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-02-27 12:40:44 +00:00
|
|
|
|
|
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();
|
|
|
|
|
});
|
2022-02-25 06:04:54 +00:00
|
|
|
|
}
|