lcy
8 天以前 485db99b5c51a971c173664cf6e808dc8424b0a0
Main/Utility/UniTaskExtension.cs
@@ -4,19 +4,55 @@
public static class UniTaskExtension
{
   public static void DelayFrame(this GameObject go, Action action)
    public static void DelayFrame(this GameObject go, Action action)
    {
        DelayFrameInternal(action);
        DelayFrameInternal(1, action);
    }
   public static void DelayFrame(this Component cmp, Action action)
    public static void DelayFrame(this Component cmp, Action action)
    {
        DelayFrameInternal(action);
        DelayFrameInternal(1, action);
    }
    private async static UniTask DelayFrameInternal(Action action)
    private async static UniTask DelayFrameInternal(int frame, Action action)
    {
        await UniTask.DelayFrame(1);
        await UniTask.DelayFrame(frame);
        action?.Invoke();
    }
    public static void DelayFrames(this Component cmp, int frames, Action action)
    {
        DelayFrameInternal(frames, action);
    }
    public static void DelayFrames(this GameObject go, int frames, Action action)
    {
        DelayFrameInternal(frames, action);
    }
    public static void DelayFrame(Action action)
    {
        DelayFrameInternal(1, action);
    }
    public static void DelayTime(this GameObject go, float time, Action action)
    {
        DelayTimeInternal(time, action);
    }
    public static void DelayTime(this Component cmp, float time, Action action)
    {
        DelayTimeInternal(time, action);
    }
    private async static UniTask DelayTimeInternal(float time, Action action)
    {
        if (time <= 0f)
        {
            action?.Invoke();
            return;
        }
        await UniTask.Delay(TimeSpan.FromSeconds(time));
        action?.Invoke();
    }
}