hch
2025-09-03 a963e7aa3d1c7a69f803405e203390b3fb43c8c5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using UnityEngine;
using Cysharp.Threading.Tasks;
using System;
 
public static class UniTaskExtension
{
    public static void DelayFrame(this GameObject go, Action action)
    {
        DelayFrameInternal(1, action);
    }
 
    public static void DelayFrame(this Component cmp, Action action)
    {
        DelayFrameInternal(1, action);
    }
 
    private async static UniTask DelayFrameInternal(int frame, Action action)
    {
        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();
    }
}