Skip to content

Commit ade8fe6

Browse files
committed
Merge branch 'feature/action-wait' into develop
2 parents 484a1e5 + a4fea9e commit ade8fe6

File tree

6 files changed

+99
-1
lines changed

6 files changed

+99
-1
lines changed

Assets/FluidBehaviorTree/Scripts/BehaviorTree/BehaviorTreeBuilder.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@ public BehaviorTreeBuilder RandomChance (int chance, int outOf) {
112112
return RandomChance("random chance", chance, outOf);
113113
}
114114

115+
public BehaviorTreeBuilder Wait (string name, int turns = 1) {
116+
_tree.AddNode(Pointer, new Wait {
117+
Name = name,
118+
turns = turns
119+
});
120+
121+
return this;
122+
}
123+
124+
public BehaviorTreeBuilder Wait (int turns = 1) {
125+
return Wait("wait", turns);
126+
}
127+
115128
public BehaviorTreeBuilder End () {
116129
_pointer.RemoveAt(_pointer.Count - 1);
117130

Assets/FluidBehaviorTree/Scripts/BehaviorTree/Editor/BehaviorTreeBuilderTest.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public class RandomChanceMethod : BehaviorTreeBuilderTest {
375375
public void It_should_add_a_random_chance () {
376376
var tree = _builder
377377
.Sequence()
378-
.RandomChance("random", 1, 3)
378+
.RandomChance("random", 1, 1)
379379
.Do("action", () => {
380380
_invokeCount++;
381381
return TaskStatus.Success;
@@ -391,5 +391,29 @@ public void It_should_add_a_random_chance () {
391391
Assert.AreEqual(1, _invokeCount);
392392
}
393393
}
394+
395+
public class WaitMethod : BehaviorTreeBuilderTest {
396+
[Test]
397+
public void It_should_add_a_wait_node () {
398+
var tree = _builder
399+
.Sequence()
400+
.Wait("wait", 2)
401+
.Do("action", () => {
402+
_invokeCount++;
403+
return TaskStatus.Success;
404+
})
405+
.Build();
406+
407+
var sequence = tree.Root.Children[0] as Sequence;
408+
var wait = sequence.Children[0] as Wait;
409+
410+
Assert.IsNotNull(wait);
411+
Assert.AreEqual(sequence.Children.Count, 2);
412+
Assert.AreEqual(TaskStatus.Continue, tree.Tick());
413+
Assert.AreEqual(TaskStatus.Continue, tree.Tick());
414+
Assert.AreEqual(TaskStatus.Success, tree.Tick());
415+
Assert.AreEqual(1, _invokeCount);
416+
}
417+
}
394418
}
395419
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using NUnit.Framework;
2+
3+
namespace Adnc.FluidBT.Tasks.Actions.Testing {
4+
public class WaitTest {
5+
[Test]
6+
public void It_should_trigger_continue_on_first_tick () {
7+
var wait = new Wait();
8+
9+
Assert.AreEqual(TaskStatus.Continue, wait.Update());
10+
}
11+
12+
[Test]
13+
public void It_should_trigger_success_on_2nd_tick () {
14+
var wait = new Wait();
15+
16+
Assert.AreEqual(TaskStatus.Continue, wait.Update());
17+
Assert.AreEqual(TaskStatus.Success, wait.Update());
18+
}
19+
20+
[Test]
21+
public void It_should_trigger_success_after_2_ticks () {
22+
var wait = new Wait {
23+
turns = 2
24+
};
25+
26+
Assert.AreEqual(TaskStatus.Continue, wait.Update());
27+
Assert.AreEqual(TaskStatus.Continue, wait.Update());
28+
Assert.AreEqual(TaskStatus.Success, wait.Update());
29+
}
30+
}
31+
}

Assets/FluidBehaviorTree/Scripts/Tasks/Actions/Editor/WaitTest.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Adnc.FluidBT.Tasks.Actions {
2+
public class Wait : ActionBase {
3+
public int turns = 1;
4+
5+
private int _ticks;
6+
7+
protected override TaskStatus OnUpdate () {
8+
if (_ticks < turns) {
9+
_ticks++;
10+
return TaskStatus.Continue;
11+
}
12+
13+
return TaskStatus.Success;
14+
}
15+
}
16+
}

Assets/FluidBehaviorTree/Scripts/Tasks/Actions/Wait.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)