-
Notifications
You must be signed in to change notification settings - Fork 195
/
Wait.cs
89 lines (80 loc) · 2.31 KB
/
Wait.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
80
81
82
83
84
85
86
87
88
89
namespace NPBehave
{
public class Wait : Task
{
private System.Func<float> function = null;
private string blackboardKey = null;
private float seconds = -1f;
private float randomVariance;
public float RandomVariance
{
get
{
return randomVariance;
}
set
{
randomVariance = value;
}
}
public Wait(float seconds, float randomVariance) : base("Wait")
{
UnityEngine.Assertions.Assert.IsTrue(seconds >= 0);
this.seconds = seconds;
this.randomVariance = randomVariance;
}
public Wait(float seconds) : base("Wait")
{
this.seconds = seconds;
this.randomVariance = this.seconds * 0.05f;
}
public Wait(string blackboardKey, float randomVariance = 0f) : base("Wait")
{
this.blackboardKey = blackboardKey;
this.randomVariance = randomVariance;
}
public Wait(System.Func<float> function, float randomVariance = 0f) : base("Wait")
{
this.function = function;
this.randomVariance = randomVariance;
}
protected override void DoStart()
{
float seconds = this.seconds;
if (seconds < 0)
{
if (this.blackboardKey != null)
{
seconds = Blackboard.Get<float>(this.blackboardKey);
}
else if (this.function != null)
{
seconds = this.function();
}
}
// UnityEngine.Assertions.Assert.IsTrue(seconds >= 0);
if (seconds < 0)
{
seconds = 0;
}
if (randomVariance >= 0f)
{
Clock.AddTimer(seconds, randomVariance, 0, onTimer);
}
else
{
Clock.AddTimer(seconds, 0, onTimer);
}
}
protected override void DoStop()
{
Clock.RemoveTimer(onTimer);
this.Stopped(false);
}
private void onTimer()
{
Clock.RemoveTimer(onTimer);
this.Stopped(true);
}
}
}