-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathCondition.cs
47 lines (40 loc) · 1.41 KB
/
Condition.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
using System;
namespace NPBehave
{
public class Condition : ObservingDecorator
{
private Func<bool> condition;
private float checkInterval;
private float checkVariance;
public Condition(Func<bool> condition, Node decoratee) : base("Condition", Stops.NONE, decoratee)
{
this.condition = condition;
this.checkInterval = 0.0f;
this.checkVariance = 0.0f;
}
public Condition(Func<bool> condition, Stops stopsOnChange, Node decoratee) : base("Condition", stopsOnChange, decoratee)
{
this.condition = condition;
this.checkInterval = 0.0f;
this.checkVariance = 0.0f;
}
public Condition(Func<bool> condition, Stops stopsOnChange, float checkInterval, float randomVariance, Node decoratee) : base("Condition", stopsOnChange, decoratee)
{
this.condition = condition;
this.checkInterval = checkInterval;
this.checkVariance = randomVariance;
}
override protected void StartObserving()
{
this.RootNode.Clock.AddTimer(checkInterval, checkVariance, -1, Evaluate);
}
override protected void StopObserving()
{
this.RootNode.Clock.RemoveTimer(Evaluate);
}
protected override bool IsConditionMet()
{
return this.condition();
}
}
}