-
Notifications
You must be signed in to change notification settings - Fork 2
/
TimerExt.cs
79 lines (71 loc) · 2.49 KB
/
TimerExt.cs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using Godot;
using JetBrains.Annotations;
namespace GodotExt
{
/// <summary>
/// This class contains functions that revolve around timers and waiting for things.
/// </summary>
[PublicAPI]
public static class TimerExt
{
/// <summary>
/// Creates a one-off timer for the given amount of time that can be awaited.
/// </summary>
[MustUseReturnValue]
[Obsolete("use SleepSeconds instead")]
public static SignalAwaiter Sleep(this Node source, float sleepTime)
{
return source.SleepSeconds(sleepTime);
}
/// <summary>
/// Creates a one-off timer for the given amount of time that can be awaited.
/// </summary>
[MustUseReturnValue]
public static SignalAwaiter SleepSeconds(this Node source, float sleepTime)
{
GdAssert.That(source.IsInsideTree(), "source.IsInsideTree()");
return source.GetTree().CreateTimer(sleepTime).Timeout();
}
/// <summary>
/// Creates a one-off timer for the given amount of time that can be awaited.
/// </summary>
[MustUseReturnValue]
public static SignalAwaiter SleepSeconds(this SceneTree source, float sleepTime)
{
return source.CreateTimer(sleepTime).Timeout();
}
/// <summary>
/// Returns a <see cref="SignalAwaiter"/> that waits until this Timer
/// runs into a timeout.
/// </summary>
public static SignalAwaiter Timeout(this SceneTreeTimer timer)
{
return timer.FiresSignal("timeout");
}
/// <summary>
/// Returns a <see cref="SignalAwaiter"/> that waits until this Timer
/// runs into a timeout.
/// </summary>
public static SignalAwaiter Timeout(this Timer timer)
{
return timer.FiresSignal("timeout");
}
/// <summary>
/// Returns a <see cref="SignalAwaiter"/> that waits until the next frame.
/// </summary>
public static SignalAwaiter NextFrame(this SceneTree tree)
{
return tree.FiresSignal("idle_frame");
}
/// <summary>
/// Returns a <see cref="SignalAwaiter"/> that waits until the next frame.
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
public static SignalAwaiter NextFrame(this Node node)
{
return node.GetTree().NextFrame();
}
}
}