关于unity延迟执行网上也有很多了,我这里只是封装下,让写代码变得更加优雅,使用更加方便。
一个问题想要表述清楚,读者也能看明白,无非3个点:What(要说的是什么),How(怎么用你这个东西?什么情况下有用?),Why(为什么要这么做,这么做有啥好处?我不这么用可以不可以?等等)
首先来看 what,直接上代码了
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class StaticUtils
{
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 delaySec