You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Assets/FluidBehaviorTree/Scripts/BehaviorTree/Builder/Editor/BehaviorTreeBuilderExtensionCompositesTest.cs
+[Your First Custom Node and Tree](#your-first-custom-node-and-tree)
92
+
+[Your First Custom Node and Tree](#your-first-custom-node-and-extension)
93
93
+[Custom Actions](#custom-actions)
94
94
+[Custom Conditions](#custom-conditions)
95
95
+[Custom Composites](#custom-composites)
@@ -317,11 +317,10 @@ public class MyCustomAi : MonoBehaviour {
317
317
318
318
## Creating Custom Reusable Nodes
319
319
320
-
What makes Fluid Behavior Tree so powerful is the ability to write your own nodes and extend the tree builder to inject
321
-
custom parameters. For example we can write a new tree builder method like this that sets the target of your AI system.
320
+
What makes Fluid Behavior Tree so powerful is the ability to write your own nodes and add them to the builder without editing any source. You can even create Unity packages that add new builder functionality. For example we can write a new tree builder method like this that sets the target of your AI system with just a few lines of code.
322
321
323
322
```C#
324
-
vartree=newTreeBuilderCustom(gameObject)
323
+
vartree=newBehaviorTreeBuilder(gameObject)
325
324
.Sequence()
326
325
.AgentDestination("Find Enemy", target)
327
326
.Do(() => {
@@ -332,10 +331,9 @@ var tree = new TreeBuilderCustom(gameObject)
332
331
.Build();
333
332
```
334
333
335
-
### Your First Custom Node and Tree
334
+
### Your First Custom Node and Extension
336
335
337
-
It should take about 10 minutes to setup your first custom
338
-
action and extend the pre-existing behavior tree builder script.
336
+
It should take about 3 minutes to create your first custom action and implement it. First create a new action.
339
337
340
338
```C#
341
339
usingAdnc.FluidBT.Tasks;
@@ -344,56 +342,36 @@ using UnityEngine;
344
342
usingUnityEngine.AI;
345
343
346
344
publicclassAgentDestination : ActionBase {
347
-
publicNavMeshAgentagent;
345
+
privateNavMeshAgent_agent;
348
346
publicTransformtarget;
349
347
350
348
protectedoverridevoidOnInit () {
351
-
agent=Owner.GetComponent<NavMeshAgent>();
349
+
_agent=Owner.GetComponent<NavMeshAgent>();
352
350
}
353
351
354
352
protectedoverrideTaskStatusOnUpdate () {
355
-
agent.SetDestination(target.position);
353
+
_agent.SetDestination(target.position);
356
354
returnTaskStatus.Success;
357
355
}
358
356
}
359
357
```
360
358
361
-
New method added to the builder script. This is pretty simple and easy to customize since most of the overhead is
362
-
abstracted away.
359
+
Next we need to extend the `BehaviorTreeBuilder` script with our new AgentDestination action. For more information on C# class extensions see the [official docs](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods).
Be sure when you create trees that you use your new `TreeBuilderCustom` class. For example:
385
-
386
-
```C#
387
-
_tree=newTreeBuilderCustom(gameObject)
388
-
.Sequence()
389
-
.AgentDestination("Find Target", target)
390
-
...
391
-
.End()
392
-
.Build();
393
-
```
394
-
395
-
And you're done! You've now created a custom action and extendable behavior tree builder. The following examples
396
-
will be more of the same. But each covers a different node type.
374
+
And you're done! You've now created a custom action and extendable behavior tree builder that's future proofed for new versions. The following examples will be more of the same. But each covers a different node type.
397
375
398
376
### Custom Actions
399
377
@@ -427,22 +405,16 @@ public class CustomAction : ActionBase {
@@ -587,7 +511,7 @@ Decorators can also be custom written to cut down on repetitive code.
587
511
usingAdnc.FluidBT.Decorators;
588
512
usingAdnc.FluidBT.Tasks;
589
513
590
-
publicclassInverter : DecoratorBase {
514
+
publicclassCustomInverter : DecoratorBase {
591
515
protectedoverrideTaskStatusOnUpdate () {
592
516
if (Child==null) {
593
517
returnTaskStatus.Success;
@@ -610,25 +534,15 @@ public class Inverter : DecoratorBase {
610
534
}
611
535
```
612
536
613
-
Implementing decorators is similar to composites (alternative commented out code for more complex integration).
614
-
See the commented area for more details.
537
+
Implementing decorators is similar to composites. If you need to set arguments on the composite you'll want to take a loot at the method `BehaviorTreeBuilder.AddNodeWithPointer()`.
0 commit comments