Skip to content

Commit 30e90f9

Browse files
committed
Added docs for splicing
1 parent dce51eb commit 30e90f9

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

Assets/FluidBehaviorTree/Scripts/BehaviorTree/BehaviorTreeBuilderBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ public T Wait (int turns = 1) {
130130
return Wait("wait", turns);
131131
}
132132

133+
public T Splice (BehaviorTree tree) {
134+
_tree.Splice(Pointer, tree);
135+
136+
return (T)this;
137+
}
138+
133139
public T End () {
134140
_pointer.RemoveAt(_pointer.Count - 1);
135141

README.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,42 @@ Does not change `TaskStatus.Continue`.
251251

252252
## Creating Reusable Behavior Trees
253253

254-
@TODO Document splicing with an example
254+
Trees can be combined with just a few line of code. This can allow you to create injectable template that bundles different
255+
nodes for complex functionality such as searching or attacking.
256+
257+
Be warned that spliced trees require a newly built tree for injection, as nodes are not deep copied on splice.
258+
259+
```C#
260+
using Adnc.FluidBT.Trees;
261+
using UnityEngine;
262+
263+
public class MyCustomAi : MonoBehaviour {
264+
private BehaviorTree _tree;
265+
266+
private void Awake () {
267+
var injectTree = new BehaviorTreeBuilder(gameObject)
268+
.Sequence()
269+
.Do("Custom Action", () => {
270+
return TaskStatus.Success;
271+
})
272+
.End();
273+
274+
_tree = new BehaviorTreeBuilder(gameObject)
275+
.Sequence()
276+
.Splice(injectTree.Build())
277+
.Do("Custom Action", () => {
278+
return TaskStatus.Success;
279+
})
280+
.End()
281+
.Build();
282+
}
283+
284+
private void Update () {
285+
// Update our tree every frame
286+
_tree.Tick();
287+
}
288+
}
289+
```
255290

256291
## Creating Custom Reusable Nodes
257292

@@ -554,7 +589,7 @@ public class TreeBuilderCustom : BehaviorTreeBuilderBase<TreeBuilderCustom> {
554589
public TreeBuilderCustom (GameObject owner) : base(owner) {
555590
}
556591

557-
public TreeBuilderCustom (string name = "My Custom Decorator") {
592+
public TreeBuilderCustom CustomDecorator (string name = "My Custom Decorator") {
558593
return ParentTask<CustomDecorator>(name);
559594

560595
// Or you can code this manually if you need more specifics

0 commit comments

Comments
 (0)