50 lines
1.5 KiB
C#
50 lines
1.5 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 void ActionAtNextFrame(this MonoBehaviour mono, Action action) => mono.StartCoroutine(ActionAtNextFrame(action));
|
|
public static IEnumerator ActionAtNextFrame(Action action)
|
|
{
|
|
yield return null;
|
|
action?.Invoke();
|
|
}
|
|
|
|
public static void ActionAfterTime(this MonoBehaviour mono, float time, Action action) => mono.StartCoroutine(ActionAfterTime(time, action));
|
|
|
|
public static IEnumerator ActionAfterTime(float time, Action action)
|
|
{
|
|
yield return new WaitForSeconds(time);
|
|
action?.Invoke();
|
|
}
|
|
}
|
|
} |