Skip to content

Commit 89f9200

Browse files
committed
Nodes now get a reference to the Behavior Tree
1 parent a62e734 commit 89f9200

File tree

7 files changed

+23
-3
lines changed

7 files changed

+23
-3
lines changed

Assets/FluidBehaviorTree/Editor/Testing/BehaviorTree/BehaviorTreeTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ public void Add_child_node_to_node_list () {
8282
public void Add_child_node_to_nodes () {
8383
Assert.IsTrue(tree.nodes.Contains(action));
8484
}
85+
86+
[Test]
87+
public void Attaches_a_reference_to_the_behavior_tree () {
88+
action.Received().Owner = tree;
89+
}
8590
}
8691

8792
public class AddNodeMethodError : AddNodeMethod {

Assets/FluidBehaviorTree/Editor/Testing/Tasks/ConditionGenericTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Adnc.FluidBT.Tasks;
2-
using Adnc.FluidBT.Tasks.Actions;
32
using NUnit.Framework;
43

54
namespace Adnc.FluidBT.Testing {

Assets/FluidBehaviorTree/Scripts/BehaviorTree/BehaviorTree.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public void AddNode (ITaskParent parent, ITask child) {
4040

4141
parent.AddChild(child);
4242
nodes.Add(child);
43+
child.Owner = this;
4344

4445
var item = child as IEventAwake;
4546
if (item != null) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Adnc.FluidBT.Tasks;
2+
using Adnc.FluidBT.Trees;
23

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

1314
public bool IsLowerPriority { get; } = false;
15+
public BehaviorTree Owner { get; set; }
1416
public TaskStatus LastStatus { get; private set; }
1517

1618
public TaskStatus Update () {

Assets/FluidBehaviorTree/Scripts/TaskParents/TaskParentBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using Adnc.FluidBT.Tasks;
3+
using Adnc.FluidBT.Trees;
34

45
namespace Adnc.FluidBT.TaskParents {
56
public abstract class TaskParentBase : ITaskParent {
@@ -18,6 +19,7 @@ public bool Enabled {
1819
protected virtual int MaxChildren { get; } = -1;
1920

2021
public bool IsLowerPriority => AbortType.HasFlag(AbortType.LowerPriority);
22+
public BehaviorTree Owner { get; set; }
2123
public bool ValidAbortCondition { get; } = false;
2224

2325
public TaskStatus Update () {

Assets/FluidBehaviorTree/Scripts/Tasks/ITask.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Adnc.FluidBT.Tasks {
1+
using Adnc.FluidBT.Trees;
2+
3+
namespace Adnc.FluidBT.Tasks {
24
public interface ITask {
35
/// <summary>
46
/// Is this task enabled or not? Disabled tasks are excluded from the runtime
@@ -10,6 +12,12 @@ public interface ITask {
1012
/// </summary>
1113
bool IsLowerPriority { get; }
1214

15+
/// <summary>
16+
/// Reference to the behavior tree responsible for this node. Allows for dynamic variables such as adding a
17+
/// GameObject reference
18+
/// </summary>
19+
BehaviorTree Owner { get; set; }
20+
1321
/// <summary>
1422
/// Last status returned by Update
1523
/// </summary>

Assets/FluidBehaviorTree/Scripts/Tasks/TaskBase.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Adnc.FluidBT.Tasks {
1+
using Adnc.FluidBT.Trees;
2+
3+
namespace Adnc.FluidBT.Tasks {
24
public abstract class TaskBase : ITask {
35
private bool _init;
46
private bool _start;
@@ -9,6 +11,7 @@ public abstract class TaskBase : ITask {
911
public TaskStatus LastStatus { get; private set; }
1012

1113
public bool IsLowerPriority { get; } = false;
14+
public BehaviorTree Owner { get; set; }
1215

1316
public TaskStatus Update () {
1417
if (!_init) {

0 commit comments

Comments
 (0)