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:40:28 +00:00
|
|
|
|
public static void RunNextFrame(Action action) => UniTask.Create(async () =>
|
2022-01-29 09:23:29 +00:00
|
|
|
|
{
|
2022-01-29 10:03:31 +00:00
|
|
|
|
await UniTask.WaitForEndOfFrame();
|
2022-01-29 09:23:29 +00:00
|
|
|
|
action();
|
|
|
|
|
});
|
|
|
|
|
|
2022-01-29 09:40:28 +00:00
|
|
|
|
public static void RunFramesLater(int n, Action action) => UniTask.Create(async () =>
|
2022-01-29 09:23:29 +00:00
|
|
|
|
{
|
2022-01-29 10:03:31 +00:00
|
|
|
|
for (var i = 0; i < n; i++)
|
|
|
|
|
{
|
|
|
|
|
await UniTask.WaitForEndOfFrame();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-29 09:31:47 +00:00
|
|
|
|
action();
|
2022-01-29 09:23:29 +00:00
|
|
|
|
});
|
2022-01-29 09:31:05 +00:00
|
|
|
|
|
2022-01-29 09:40:28 +00:00
|
|
|
|
public static void RunWhen(Func<bool> predicate, Action action) => UniTask.Create(async () =>
|
2022-01-29 09:31:05 +00:00
|
|
|
|
{
|
2022-01-29 10:03:31 +00:00
|
|
|
|
await UniTask.WaitUntil(predicate);
|
2022-01-29 09:31:05 +00:00
|
|
|
|
action();
|
|
|
|
|
});
|
2022-01-29 09:23:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|