Skip to content

Commit f4daa54

Browse files
committed
Nodes now automatically reset if the tick count changes
1 parent 9fd3f2b commit f4daa54

29 files changed

+66
-89
lines changed

Assets/FluidBehaviorTree/Editor/Builders/TaskStubBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public TaskStubBuilder WithUpdateStatus (TaskStatus status) {
2222
public ITask Build () {
2323
var task = Substitute.For<ITask>();
2424
task.Enabled.Returns(_enabled);
25-
task.Update().Returns(_status);
25+
task.Update().ReturnsForAnyArgs(_status);
2626

2727
return task;
2828
}

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ public void Update_the_first_child_task_on_update () {
7171
_action.Received(1).Update();
7272
}
7373

74-
[Test]
75-
public void Runs_reset_on_2nd_run_if_success () {
76-
_tree.Tick();
77-
_tree.Tick();
78-
79-
_action.Received(1).Reset();
80-
}
81-
8274
[Test]
8375
public void Does_not_run_reset_on_2nd_run_if_continue_was_returned () {
8476
_action.Update().Returns(TaskStatus.Continue);
@@ -140,16 +132,6 @@ public void Runs_all_actions_again_on_2nd_pass () {
140132

141133
_sequence.Children.ForEach((child) => child.Received(2).Update());
142134
}
143-
144-
[Test]
145-
public void Runs_reset_2x_on_first_action_if_it_fails () {
146-
_action.Update().Returns(TaskStatus.Failure);
147-
148-
_tree.Tick();
149-
_tree.Tick();
150-
151-
_action.Received(1).Reset();
152-
}
153135

154136
[Test]
155137
public void Does_not_run_reset_on_2nd_action_if_1st_fails () {

Assets/FluidBehaviorTree/Scripts/BehaviorTree/Tree.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@
55
namespace Adnc.FluidBT.Trees {
66
public class Tree {
77
private readonly GameObject _owner;
8-
private TaskStatus _lastStatus;
9-
private int _tickCount;
8+
9+
public int TickCount { get; private set; }
1010

1111
public TaskRoot Root { get; } = new TaskRoot();
1212

1313
public Tree (GameObject owner) {
1414
_owner = owner;
15+
Root.ParentTree = this;
1516
Root.Owner = owner;
1617
}
1718

1819
public void AddNode (ITaskParent parent, ITask child) {
1920
parent.AddChild(child);
21+
child.ParentTree = this;
2022
child.Owner = _owner;
2123
}
2224

2325
public void Tick () {
24-
_lastStatus = Root.Update();
25-
_tickCount++;
26-
27-
// Possible way to automate triggering reset
28-
// _lastStatus = Root.Update(_tickCount != 0 && _lastStatus != TaskStatus.Continue);
26+
if (Root.Update() != TaskStatus.Continue) {
27+
TickCount++;
28+
}
2929
}
3030
}
3131
}

Assets/FluidBehaviorTree/Scripts/TaskParents/Decorators.meta renamed to Assets/FluidBehaviorTree/Scripts/Decorators.meta

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

Assets/FluidBehaviorTree/Scripts/TaskParents/Decorators/DecoratorBase.cs renamed to Assets/FluidBehaviorTree/Scripts/Decorators/DecoratorBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Adnc.FluidBT.Tasks;
22
using UnityEngine;
3+
using Tree = Adnc.FluidBT.Trees.Tree;
34

45
namespace Adnc.FluidBT.Decorators {
56
public abstract class DecoratorBase : ITask {
@@ -12,6 +13,7 @@ public bool Enabled {
1213
}
1314

1415
public GameObject Owner { get; set; }
16+
public Tree ParentTree { get; set; }
1517
public TaskStatus LastStatus { get; private set; }
1618

1719
public TaskStatus Update () {
@@ -28,7 +30,6 @@ public void End () {
2830
}
2931

3032
public void Reset (bool hardReset = false) {
31-
child.Reset();
3233
}
3334
}
3435
}
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)