38 lines
998 B
C#
38 lines
998 B
C#
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public static class DelayToDoUtils
|
|
{
|
|
public static Coroutine DelayToDo(this MonoBehaviour mono, float delayTime, Action action, bool ignoreTimeScale = false)
|
|
{
|
|
Coroutine coroutine = null;
|
|
if (ignoreTimeScale)
|
|
{
|
|
coroutine = mono.StartCoroutine(DelayIgnoreTimeToDo(delayTime, action));
|
|
}
|
|
else
|
|
{
|
|
coroutine = mono.StartCoroutine(DelayToInvokeDo(delayTime, action));
|
|
|
|
}
|
|
return coroutine;
|
|
}
|
|
|
|
public static IEnumerator DelayToInvokeDo(float delaySeconds, Action action)
|
|
{
|
|
yield return new WaitForSeconds(delaySeconds);
|
|
action();
|
|
}
|
|
|
|
public static IEnumerator DelayIgnoreTimeToDo(float delaySeconds, Action action)
|
|
{
|
|
float start = Time.realtimeSinceStartup;
|
|
while (Time.realtimeSinceStartup < start + delaySeconds)
|
|
{
|
|
yield return null;
|
|
}
|
|
action();
|
|
}
|
|
}
|