Skip to content

Commit f429d91

Browse files
committed
Added generic decorator node
1 parent 8364bcb commit f429d91

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Adnc.FluidBT.Decorators;
2+
using Adnc.FluidBT.Tasks;
3+
using NUnit.Framework;
4+
5+
namespace Adnc.FluidBT.Testing {
6+
public class DecoratorGenericTest {
7+
public class UpdateMethod {
8+
[Test]
9+
public void Can_invert_status_of_child () {
10+
var task = new DecoratorGeneric {
11+
child = A.TaskStub().Build(),
12+
updateLogic = (dec) => {
13+
if (dec.child.Update() == TaskStatus.Success) {
14+
return TaskStatus.Failure;
15+
}
16+
17+
return TaskStatus.Success;
18+
}
19+
};
20+
21+
Assert.AreEqual(TaskStatus.Failure, task.Update());
22+
}
23+
24+
[Test]
25+
public void Returns_child_status_without_update_logic () {
26+
var task = new DecoratorGeneric {
27+
child = A.TaskStub().Build()
28+
};
29+
30+
Assert.AreEqual(TaskStatus.Success, task.Update());
31+
}
32+
}
33+
}
34+
}

Assets/FluidBehaviorTree/Editor/Testing/Decorators/DecoratorGenericTest.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+
using System;
2+
using Adnc.FluidBT.Tasks;
3+
4+
namespace Adnc.FluidBT.Decorators {
5+
public class DecoratorGeneric : DecoratorBase {
6+
public Func<DecoratorBase, TaskStatus> updateLogic;
7+
8+
protected override TaskStatus OnUpdate () {
9+
if (updateLogic != null) {
10+
return updateLogic(this);
11+
}
12+
13+
return child.Update();
14+
}
15+
}
16+
}

Assets/FluidBehaviorTree/Scripts/TaskParents/Decorators/DecoratorGeneric.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.

0 commit comments

Comments
 (0)