Skip to content

Commit 8364bcb

Browse files
committed
Added condition generic
1 parent 5e51dd0 commit 8364bcb

File tree

4 files changed

+97
-0
lines changed

4 files changed

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

Assets/FluidBehaviorTree/Editor/Testing/Tasks/ConditionGenericTest.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 {
4+
public class ConditionGeneric : ConditionBase {
5+
public Func<bool> updateLogic;
6+
public Action startLogic;
7+
public Action initLogic;
8+
public Action exitLogic;
9+
10+
protected override bool OnUpdate () {
11+
if (updateLogic != null) {
12+
return updateLogic();
13+
}
14+
15+
return true;
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/Conditions/ConditionGeneric.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)