Skip to content

Commit 5e51dd0

Browse files
committed
New generic action with hookable events
1 parent 57a9748 commit 5e51dd0

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using Adnc.FluidBT.Tasks;
2+
using Adnc.FluidBT.Tasks.Actions;
3+
using NUnit.Framework;
4+
5+
namespace Adnc.FluidBT.Testing {
6+
public class ActionGenericTest {
7+
public class UpdateMethod {
8+
[Test]
9+
public void It_should_execute_a_generic_function () {
10+
var task = new ActionGeneric {
11+
updateLogic = () => TaskStatus.Failure
12+
};
13+
14+
Assert.AreEqual(TaskStatus.Failure, task.Update());
15+
}
16+
17+
[Test]
18+
public void It_should_not_fail_without_a_generic_function () {
19+
var task = new ActionGeneric();
20+
task.Update();
21+
}
22+
23+
[Test]
24+
public void It_should_execute_a_start_hook () {
25+
var test = 0;
26+
var task = new ActionGeneric {
27+
startLogic = () => { test++; }
28+
};
29+
30+
task.Update();
31+
32+
Assert.AreEqual(1, test);
33+
}
34+
35+
[Test]
36+
public void It_should_execute_a_init_hook () {
37+
var test = 0;
38+
var task = new ActionGeneric {
39+
initLogic = () => { test++; }
40+
};
41+
42+
task.Update();
43+
44+
Assert.AreEqual(1, test);
45+
}
46+
47+
[Test]
48+
public void It_should_execute_a_exit_hook () {
49+
var test = 0;
50+
var task = new ActionGeneric {
51+
exitLogic = () => { test++; }
52+
};
53+
54+
task.Update();
55+
56+
Assert.AreEqual(1, test);
57+
}
58+
}
59+
}
60+
}

Assets/FluidBehaviorTree/Editor/Testing/Tasks/ActionGenericTest.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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
3+
namespace Adnc.FluidBT.Tasks.Actions {
4+
public class ActionGeneric : ActionBase {
5+
public Func<TaskStatus> updateLogic;
6+
public Action startLogic;
7+
public Action initLogic;
8+
public Action exitLogic;
9+
10+
protected override TaskStatus OnUpdate () {
11+
if (updateLogic != null) {
12+
return updateLogic();
13+
}
14+
15+
return TaskStatus.Success;
16+
}
17+
18+
protected override void OnStart () {
19+
startLogic?.Invoke();
20+
}
21+
22+
protected override void OnExit () {
23+
initLogic?.Invoke();
24+
}
25+
26+
protected override void OnInit () {
27+
exitLogic?.Invoke();
28+
}
29+
}
30+
}

Assets/FluidBehaviorTree/Scripts/Tasks/Actions/ActionGeneric.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)