Skip to content

Commit ee51211

Browse files
committed
docs(readme): quickstart extending trees example
1 parent 111ad23 commit ee51211

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

README.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,38 @@ Depending on what you return for a task status different things will happen.
8181
* Failure: Same as success, except informs that the node failed
8282
* Continue: Rerun this node the next time `tree.Tick()` is called. A pointer reference is tracked by the tree and can only be cleared if `tree.Reset()` is called.
8383

84-
### WTF is a Behavior Tree?
84+
### Extending Trees
8585

86-
If you aren't super familiar with behavior trees you might want to watch this video.
86+
You can safely add new code to your behavior trees with several lines. Allowing you to customize BTs while supporting future version upgrades.
8787

88-
https://www.youtube.com/watch?v=YCMvUCxzWz8
88+
```c#
89+
using UnityEngine;
90+
using CleverCrow.Fluid.BTs.Tasks;
91+
using CleverCrow.Fluid.BTs.Tasks.Actions;
92+
using CleverCrow.Fluid.BTs.Trees;
93+
94+
public class CustomAction : ActionBase {
95+
protected override TaskStatus OnUpdate () {
96+
Debug.Log(Owner.name);
97+
return TaskStatus.Success;
98+
}
99+
}
100+
101+
public static class BehaviorTreeBuilderExtensions {
102+
public static BehaviorTreeBuilder CustomAction (this BehaviorTreeBuilder builder, string name = "My Action") {
103+
return builder.AddNode(new CustomAction { Name = name });
104+
}
105+
}
106+
107+
public class ExampleUsage : MonoBehaviour {
108+
public void Awake () {
109+
var bt = new BehaviorTreeBuilder(gameObject)
110+
.Sequence()
111+
.CustomAction()
112+
.End();
113+
}
114+
}
115+
```
89116

90117
## Table of Contents
91118

0 commit comments

Comments
 (0)