Skip to content

Commit b5a4508

Browse files
authored
feat: add Unity BT debugger and node naming support (#45)
* feat: add Unity BT debugger and node naming support Add an in-Editor Behaviour Tree debugger window and runtime glue to support visualization and node naming. - Add BehaviourTreeDebuggerWindow (Editor) that visualizes behaviour trees at runtime: node layout, state colors, active path highlighting, evaluation order, and play-mode refresh/selection handling. - Add BehaviourTreeMono (Runtime) base MonoBehaviour to create and expose a BehaviourTree instance on Awake. - Add Name property and SetName(string) to INode, BehaviourNode, BehaviourRoot and EmptyBehaviourNode so nodes expose readable names (defaulting to type name) for the debugger. - Include Unity .meta files for the new Editor/Runtime files. These changes enable runtime inspection of behaviour trees in the Unity Editor and ensure nodes provide names for clearer visualization. * feat: add Name and SetName to test nodes Add a Name property and SetName(string) method stubs to the test node/root classes across the unit tests to satisfy an updated INode/IRoot interface. The Name property returns an empty string and SetName is a no-op in most test classes (TestRoot's SetName throws NotImplementedException). Updates apply to multiple files under tests/GroveGames.BehaviourTree.Tests (Composites, Decorators, RootTests, TreeTests) to prevent compilation errors after the interface change.
1 parent 780e7c6 commit b5a4508

25 files changed

Lines changed: 922 additions & 0 deletions

src/GroveGames.BehaviourTree.Unity/Packages/com.grovegames.behaviourtree/Editor/BehaviourTreeDebuggerWindow.cs

Lines changed: 768 additions & 0 deletions
Large diffs are not rendered by default.

src/GroveGames.BehaviourTree.Unity/Packages/com.grovegames.behaviourtree/Editor/BehaviourTreeDebuggerWindow.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using GroveGames.BehaviourTree.Collections;
2+
using UnityEngine;
3+
4+
namespace GroveGames.BehaviourTree.Unity
5+
{
6+
public abstract class BehaviourTreeMono : MonoBehaviour
7+
{
8+
protected BehaviourTree _tree;
9+
public BehaviourTree Tree => _tree;
10+
11+
protected abstract BehaviourTree CreateTree(Blackboard blackboard);
12+
13+
protected virtual void Awake()
14+
{
15+
var blackboard = new Blackboard();
16+
_tree = CreateTree(blackboard);
17+
}
18+
}
19+
}

src/GroveGames.BehaviourTree.Unity/Packages/com.grovegames.behaviourtree/Runtime/BehaviourTreeMono.cs.meta

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

src/GroveGames.BehaviourTree/Nodes/BehaviourNode.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ public abstract class BehaviourNode : INode
77
public static readonly INode Empty = new EmptyBehaviourNode();
88

99
private IParent _parent = null!;
10+
private string _name;
1011
protected NodeState _nodeState;
1112

1213
protected IParent Parent => _parent;
1314
public IBlackboard Blackboard => _parent.Blackboard;
1415
public NodeState State => _nodeState;
16+
public string Name => _name;
17+
18+
public BehaviourNode()
19+
{
20+
_name = GetType().Name;
21+
}
1522

1623
public virtual void SetParent(IParent parent)
1724
{
@@ -42,4 +49,8 @@ public virtual void EndEvaluate()
4249
{
4350

4451
}
52+
public void SetName(string name)
53+
{
54+
_name = name;
55+
}
4556
}

src/GroveGames.BehaviourTree/Nodes/BehaviourRoot.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ public sealed class BehaviourRoot : IRoot
77
private readonly IBlackboard _blackboard;
88
private INode _child;
99
private NodeState _nodeState;
10+
private string _name;
1011

1112
public IBlackboard Blackboard => _blackboard;
1213
public NodeState State => _nodeState;
14+
public string Name => _name;
1315

1416
public BehaviourRoot(IBlackboard blackboard)
1517
{
1618
_blackboard = blackboard;
1719
_child = BehaviourNode.Empty;
20+
_name = GetType().Name;
1821
}
1922

2023
public NodeState Evaluate(float deltaTime)
@@ -64,4 +67,9 @@ public void SetParent(IParent parent)
6467
{
6568

6669
}
70+
71+
public void SetName(string name)
72+
{
73+
_name = name;
74+
}
6775
}

src/GroveGames.BehaviourTree/Nodes/EmptyBehaviourNode.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ public sealed class EmptyBehaviourNode : INode
44
{
55
public NodeState State => NodeState.Failure;
66

7+
public string Name => string.Empty;
8+
79
public NodeState Evaluate(float deltaTime)
810
{
911
return NodeState.Failure;
@@ -33,4 +35,9 @@ public void SetParent(IParent parent)
3335
{
3436

3537
}
38+
39+
public void SetName(string name)
40+
{
41+
42+
}
3643
}

src/GroveGames.BehaviourTree/Nodes/INode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ public interface INode
88
public void StartEvaluate();
99
public void EndEvaluate();
1010
public void SetParent(IParent parent);
11+
public void SetName(string name);
1112
public NodeState State { get; }
13+
public string Name { get; }
1214
}

tests/GroveGames.BehaviourTree.Tests/Nodes/Composites/CompositeTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ private sealed class TestNode : INode
5050
public int ResetCallCount { get; private set; }
5151
public NodeState State { get; set; } = NodeState.Success;
5252

53+
public string Name => string.Empty;
54+
5355
public NodeState Evaluate(float deltaTime) => State;
5456

5557
public void Reset()
@@ -61,6 +63,10 @@ public void Abort() { }
6163
public void StartEvaluate() { }
6264
public void EndEvaluate() { }
6365
public void SetParent(IParent parent) { }
66+
67+
public void SetName(string name)
68+
{
69+
}
6470
}
6571

6672
[Fact]

tests/GroveGames.BehaviourTree.Tests/Nodes/Composites/ParallelTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ private sealed class TestNode : INode
2121
public NodeState ReturnState { get; set; } = NodeState.Success;
2222
public NodeState State => ReturnState;
2323

24+
public string Name => string.Empty;
25+
2426
public NodeState Evaluate(float deltaTime) => ReturnState;
2527
public void Reset() { }
2628
public void Abort() { }
2729
public void StartEvaluate() { }
2830
public void EndEvaluate() { }
2931
public void SetParent(IParent parent) { }
32+
33+
public void SetName(string name)
34+
{
35+
}
3036
}
3137

3238
private sealed class TestParent : IParent

0 commit comments

Comments
 (0)