Skip to content

Commit 352ef54

Browse files
committed
Finished README.md docs and tested code samples
1 parent 671c881 commit 352ef54

File tree

1 file changed

+68
-27
lines changed

1 file changed

+68
-27
lines changed

README.md

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ Inspired by Fluent Behavior Tree.
1515
Other Features
1616

1717
* Minimal runtime footprint
18-
* Tracks the last position of your Behavior Tree and restores it the next frame
18+
* Tracks the last position of your behavior tree and restores it the next frame
1919
* Documentation on how to use and extend
2020
* Open source and free
2121
* Built for Unity (no integration overhead)
2222
* Includes a usage example of CTF
2323

24+
**Need Help?**
25+
26+
Have questions or need help? Join us on Slack.
27+
28+
[Join Slack Group](https://join.slack.com/t/fluidbehaviortree/shared_invite/enQtNDI4MjM4NzA0NjMxLTAzYTAxODRjMDNlOGE4ZTBjOGExNjU3Zjg5NWFhOTM2YTEzMDY2ZjljMjY0OWJmOTU5NGY1NTc5YTk2NGM1MGM)
29+
2430
## Getting Started
2531

2632
Grab the latest `*.unitypackage` from the [releases page](https://github.com/ashblue/fluid-behavior-tree/releases).
@@ -30,8 +36,9 @@ Grab the latest `*.unitypackage` from the [releases page](https://github.com/ash
3036
When creating trees you'll need to store them in a variable to properly cache all the necessary data.
3137

3238
```C#
33-
using Adnc.FluidBT.Trees;
3439
using UnityEngine;
40+
using Adnc.FluidBT.Tasks;
41+
using Adnc.FluidBT.Trees;
3542

3643
public class MyCustomAi : MonoBehaviour {
3744
private BehaviorTree _tree;
@@ -56,7 +63,7 @@ public class MyCustomAi : MonoBehaviour {
5663
}
5764
```
5865

59-
### What a returned TaskStatus does
66+
### What a Returned TaskStatus Does
6067

6168
Depending on what you return for a task status different things will happen.
6269

@@ -66,15 +73,44 @@ Depending on what you return for a task status different things will happen.
6673

6774
### WTF is a Behavior Tree?
6875

69-
If you aren't super familiar with Behavior Trees you might want to watch this video.
76+
If you aren't super familiar with behavior trees you might want to watch this video.
7077

7178
https://www.youtube.com/watch?v=YCMvUCxzWz8
7279

80+
## Table of Contents
81+
82+
* [Getting Started](#getting-started)
83+
* [Example Scene](#example-scene)
84+
* [Library](#library)
85+
+ [Actions](#actions)
86+
- [Generic](#generic)
87+
- [Wait](#wait)
88+
+ [Conditions](#conditions)
89+
- [Generic](#generic-1)
90+
- [Random Chance](#random-chance)
91+
+ [Composites](#composites)
92+
- [Sequence](#sequence)
93+
- [Selector](#selector)
94+
- [Parallel](#parallel)
95+
+ [Decorators](#decorators)
96+
- [Generic](#generic-2)
97+
- [Inverter](#inverter)
98+
- [ReturnSuccess](#returnsuccess)
99+
- [ReturnFailure](#returnfailure)
100+
* [Creating Reusable Behavior Trees](#creating-reusable-behavior-trees)
101+
* [Creating Custom Reusable Nodes](#creating-custom-reusable-nodes)
102+
+ [Your First Custom Node and Tree](#your-first-custom-node-and-tree)
103+
+ [Custom Actions](#custom-actions)
104+
+ [Custom Conditions](#custom-conditions)
105+
+ [Custom Composites](#custom-composites)
106+
+ [Custom Decorators](#custom-decorators)
107+
* [Submitting your own actions, conditions, ect](#submitting-your-own-actions--conditions--ect)
108+
73109
## Example Scene
74110

75-
You might want to look at the capture the flag example project located at `/Assets/FluidBehaviorTree/Examples/CaptureTheFlag/CaptureTheFlag.unity`
76-
for a working example of how Fluid Behavior Tree can be used in your project. It demonstrates real time usage of this library
77-
with units who will attempt to capture the flag while grabbing power ups to try and gain the upper hand.
111+
You might want to look at the capture the flag example project `/Assets/FluidBehaviorTree/Examples/CaptureTheFlag/CaptureTheFlag.unity`
112+
for a working example of how Fluid Behavior Tree can be used in your project. It demonstrates real time usage
113+
with units who attempt to capture the flag while grabbing power ups to try and gain the upper hand.
78114

79115
## Library
80116

@@ -98,7 +134,7 @@ look into the section on writing your own custom actions.
98134

99135
#### Wait
100136

101-
Skip a number of ticks on the Behavior Tree.
137+
Skip a number of ticks on the behavior tree.
102138

103139
```C#
104140
.Sequence()
@@ -251,13 +287,14 @@ Does not change `TaskStatus.Continue`.
251287

252288
## Creating Reusable Behavior Trees
253289

254-
Trees can be combined with just a few line of code. This can allow you to create injectable template that bundles different
290+
Trees can be combined with just a few line of code. This allows you to create injectable behavior trees that bundles different
255291
nodes for complex functionality such as searching or attacking.
256292

257-
Be warned that spliced trees require a newly built tree for injection, as nodes are not deep copied on splice.
293+
Be warned that spliced trees require a newly built tree for injection, as nodes are only deep copied on `.Build()`.
258294

259295
```C#
260296
using Adnc.FluidBT.Trees;
297+
using Adnc.FluidBT.Tasks;
261298
using UnityEngine;
262299

263300
public class MyCustomAi : MonoBehaviour {
@@ -290,7 +327,8 @@ public class MyCustomAi : MonoBehaviour {
290327

291328
## Creating Custom Reusable Nodes
292329

293-
What makes Fluid Behavior Tree so powerful is the ability to write your own nodes and extend the tree builder to inject custom parameters. For example we can write a new tree builder method like this that sets the target of your AI system.
330+
What makes Fluid Behavior Tree so powerful is the ability to write your own nodes and extend the tree builder to inject
331+
custom parameters. For example we can write a new tree builder method like this that sets the target of your AI system.
294332

295333
```C#
296334
var tree = new TreeBuilderCustom(gameObject)
@@ -304,16 +342,14 @@ var tree = new TreeBuilderCustom(gameObject)
304342
.Build();
305343
```
306344

307-
We'll cover how to build this in the next section **Actions**. It should take about 10 minutes to setup your first custom
308-
action and extend the pre-existing Behavior Tree Builder.
309-
310345
### Your First Custom Node and Tree
311346

312-
Creating the custom action code is quite simple. Below you'll find a complete overview of additional
313-
methods supported by a custom action.
347+
It should take about 10 minutes to setup your first custom
348+
action and extend the pre-existing behavior tree builder script.
314349

315350
```C#
316351
using Adnc.FluidBT.Tasks;
352+
using Adnc.FluidBT.Tasks.Actions;
317353
using UnityEngine;
318354
using UnityEngine.AI;
319355

@@ -337,6 +373,7 @@ abstracted away.
337373

338374
```C#
339375
using Adnc.FluidBT.Trees;
376+
using UnityEngine;
340377

341378
public class TreeBuilderCustom : BehaviorTreeBuilderBase<TreeBuilderCustom> {
342379
// This is always required for class extension reasons (will error without)
@@ -365,7 +402,7 @@ _tree = new TreeBuilderCustom(gameObject)
365402
.Build();
366403
```
367404

368-
And you're done! You've now created a custom action and extendable Behavior Tree Builder. The following examples
405+
And you're done! You've now created a custom action and extendable behavior tree builder. The following examples
369406
will be more of the same. But each covers a different node type.
370407

371408
### Custom Actions
@@ -376,6 +413,7 @@ that you're using constantly.
376413
```C#
377414
using UnityEngine;
378415
using Adnc.FluidBT.Tasks;
416+
using Adnc.FluidBT.Tasks.Actions;
379417

380418
public class CustomAction : ActionBase {
381419
// Triggers only the first time this node is run (great for caching data)
@@ -388,7 +426,7 @@ public class CustomAction : ActionBase {
388426

389427
// Triggers every time `Tick()` is called on the tree and this node is run
390428
protected override TaskStatus OnUpdate () {
391-
// Points to the GameObject of whoever owns the Behavior Tree
429+
// Points to the GameObject of whoever owns the behavior tree
392430
Debug.Log(Owner.name);
393431
return TaskStatus.Success;
394432
}
@@ -403,6 +441,7 @@ Add your new node to a custom tree builder.
403441

404442
```C#
405443
using Adnc.FluidBT.Trees;
444+
using UnityEngine;
406445

407446
public class TreeBuilderCustom : BehaviorTreeBuilderBase<TreeBuilderCustom> {
408447
public TreeBuilderCustom (GameObject owner) : base(owner) {
@@ -438,7 +477,7 @@ public class CustomCondition : ConditionBase {
438477

439478
// Triggers every time `Tick()` is called on the tree and this node is run
440479
protected override bool OnUpdate () {
441-
// Points to the GameObject of whoever owns the Behavior Tree
480+
// Points to the GameObject of whoever owns the behavior tree
442481
Debug.Log(Owner.name);
443482
return true;
444483
}
@@ -452,6 +491,7 @@ public class CustomCondition : ConditionBase {
452491
Add the new condition to your behavior tree builder with the following snippet.
453492

454493
```C#
494+
using UnityEngine;
455495
using Adnc.FluidBT.Trees;
456496

457497
public class TreeBuilderCustom : BehaviorTreeBuilderBase<TreeBuilderCustom> {
@@ -478,6 +518,7 @@ using Adnc.FluidBT.TaskParents.Composites;
478518
using Adnc.FluidBT.Tasks;
479519
using Random = System.Random;
480520

521+
// Makes a selector randomize its order of running child tasks
481522
public class SelectorRandom : CompositeBase {
482523
private bool _init;
483524

@@ -504,7 +545,7 @@ public class SelectorRandom : CompositeBase {
504545
return TaskStatus.Failure;
505546
}
506547

507-
// Reset is triggered when the Behavior Tree ends, then runs again ticking this node
548+
// Reset is triggered when the behavior tree ends, then runs again ticking this node
508549
public override void Reset (bool hardReset = false) {
509550
base.Reset(hardReset);
510551

@@ -529,6 +570,7 @@ Adding custom composites to your behavior tree only takes a line of code. Below
529570
of code if you need more control over the parameters of your composite.
530571

531572
```C#
573+
using UnityEngine;
532574
using Adnc.FluidBT.Trees;
533575

534576
public class TreeBuilderCustom : BehaviorTreeBuilderBase<TreeBuilderCustom> {
@@ -539,11 +581,9 @@ public class TreeBuilderCustom : BehaviorTreeBuilderBase<TreeBuilderCustom> {
539581
return ParentTask<CustomComposite>(name);
540582

541583
// Or you can code this manually if you need more specifics
542-
//
543584
// var parent = new CustomComposite { Name = name };
544585
// _tree.AddNode(Pointer, parent);
545586
// _pointer.Add(parent);
546-
//
547587
// return this;
548588
}
549589
}
@@ -554,6 +594,7 @@ public class TreeBuilderCustom : BehaviorTreeBuilderBase<TreeBuilderCustom> {
554594
Decorators can also be custom written to cut down on repetitive code.
555595

556596
```C#
597+
using Adnc.FluidBT.Decorators;
557598
using Adnc.FluidBT.Tasks;
558599

559600
public class Inverter : DecoratorBase {
@@ -579,10 +620,11 @@ public class Inverter : DecoratorBase {
579620
}
580621
```
581622

582-
Implementing decorators is a lot like composites and can be done in a more complex manner if desired for more customization.
623+
Implementing decorators is similar to composites (alternative commented out code for more complex integration).
583624
See the commented area for more details.
584625

585626
```C#
627+
using UnityEngine;
586628
using Adnc.FluidBT.Trees;
587629

588630
public class TreeBuilderCustom : BehaviorTreeBuilderBase<TreeBuilderCustom> {
@@ -593,11 +635,9 @@ public class TreeBuilderCustom : BehaviorTreeBuilderBase<TreeBuilderCustom> {
593635
return ParentTask<CustomDecorator>(name);
594636

595637
// Or you can code this manually if you need more specifics
596-
//
597638
// var parent = new CustomComposite { Name = name };
598639
// _tree.AddNode(Pointer, parent);
599640
// _pointer.Add(parent);
600-
//
601641
// return this;
602642
}
603643
}
@@ -608,5 +648,6 @@ public class TreeBuilderCustom : BehaviorTreeBuilderBase<TreeBuilderCustom> {
608648
Please fill out the following details if you'd like to contribute new code to this project.
609649

610650
1. Clone this project for the core code with tests
611-
2. Make sure your new code is reasonably tested to demonstrate it works (see `*Test.cs` files)
612-
3. Submit a pull request to the `develop` branch
651+
2. Put your new code in a separate branch
652+
3. Make sure your new code is reasonably tested to demonstrate it works (see `*Test.cs` files)
653+
4. Submit a pull request to the `develop` branch

0 commit comments

Comments
 (0)