42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
namespace NEG.Utils
|
|
{
|
|
public static class CoroutineUtils
|
|
{
|
|
private static readonly WaitForEndOfFrame WaitForEndOfFrame = new WaitForEndOfFrame();
|
|
|
|
public static IEnumerator WaitForFrames(int count)
|
|
{
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
public static void ActionAfterFrames(this MonoBehaviour mono, int count, Action action)
|
|
{
|
|
mono.StartCoroutine(ActionAfterFrames(count, action));
|
|
}
|
|
|
|
public static IEnumerator ActionAfterFrames(int count, Action action)
|
|
{
|
|
yield return WaitForFrames(count);
|
|
action?.Invoke();
|
|
}
|
|
|
|
public static IEnumerator ActionAfterEndOfFrame(Action action)
|
|
{
|
|
yield return WaitForEndOfFrame;
|
|
action?.Invoke();
|
|
}
|
|
|
|
public static IEnumerator ActionAtNextFrame(Action action)
|
|
{
|
|
yield return null;
|
|
action?.Invoke();
|
|
}
|
|
}
|
|
} |