Skip to content

Commit

Permalink
Update Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
AkiKurisu committed Jun 8, 2024
1 parent 8be94d8 commit 5e49e0d
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 99 deletions.
70 changes: 70 additions & 0 deletions Docs/editor-extensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<div align="center">

# Editor Extensions

This document contains notice for extending and customizing Editor.

</div>

## How to change font

For visual effects such as fonts, colors, layout, etc, you can change the uss style file in `BehaviorTreeSetting`.

## How to customize node

For many reason, you may want to customize node like adding a button to preview effect.

You can write an editor class to provide your node which is similar to customize `Editor` in `UnityEditor`.

```C#
[Ordered]
public class SampleResolver : INodeResolver
{
//Create custom node
public IBehaviorTreeNode CreateNodeInstance(Type type)
{
return new SampleNode();
}
//Identify node type
public static bool IsAcceptable(Type behaviorType) => behaviorType == typeof(SampleClass);

//Your custom node
private class SampleNode : ActionNode
{
}
}
```

## How to customize field

Since AkiBT use GraphView as frontend which is powered by UIElement, it can not support all fields.

If you want to customize field or want to support some fields AkiBT currently not support (eg. Array), you can write an editor class to provide your field which is similar to customize `PropertyDrawer` in `UnityEditor`.

```C#
[Ordered]
public class LocalizedStringResolver : FieldResolver<LocalizedStringField,LocalizedString>
{
public LocalizedStringResolver(FieldInfo fieldInfo) : base(fieldInfo)
{
}
protected override LocalizedStringField CreateEditorField(FieldInfo fieldInfo)
{
return new LocalizedStringField(fieldInfo.Name);
}
public static bool IsAcceptable(Type infoType, FieldInfo _) => infoType == typeof(LocalizedString);

}
public class LocalizedStringField : BaseField<LocalizedString>
{

}
```

## How to use IMGUI in graph editor

If you don't want to use ui element, you can notify the field with `WarpFieldAttribute` to let editor use IMGUI as field's frontend.

## How to customize graph editor

TODO
7 changes: 7 additions & 0 deletions Docs/editor-extensions.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 18 additions & 92 deletions Docs/API.md → Docs/runtime-extensions.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
# API
<div align="center">

# Runtime Extensions

This document contains notice for using and extending nodes, SharedVariables and attributes.

</div>

- [Behavior Node Type](#behavior-node-type)
- [Built In Composite Node](#built-in-composite-node)
- [Sequence](#sequence)
- [Selector](#selector)
- [Parallel](#parallel)
- [Random](#random)
- [Rotator](#rotator)
- [Create New Behaviors](#create-new-behaviors)
- [Create Action](#create-action)
- [Create Conditional](#create-conditional)
- [Create Composite](#create-composite)
- [Create Decorator](#create-decorator)
- [Attributes](#attributes)
- [AkiInfoAttribute](#akiinfoattribute)
- [AkiLabelAttribute](#akilabelattribute)
- [AkiGroupAttribute](#akigroupattribute)
- [ForceSharedAttribute](#forcesharedattribute)
- [WrapFieldAttribute](#wrapfieldattribute)
- [Runtime Build BehaviorTree](#runtime-build-behaviortree)
- [BehaviorTree Builder](#behaviortree-builder)
- [SharedVariable](#sharedvariable)
- [How to use](#how-to-use)
- [API Reference](#api-reference)
- [Editor Extend](#editor-extend)
- [How to change font](#how-to-change-font)
- [How to customize node](#how-to-customize-node)
- [How to customize field](#how-to-customize-field)
- [How to use IMGUI in Graph Editor](#how-to-use-imgui-in-graph-editor)



## Behavior Node Type

Expand All @@ -38,9 +22,6 @@
| Conditional Node | It has one child node and check the condition whether child is updatable. when having no child, Conditional Node is the leaf node like Action Node. |
| Decorator Node | It has one child node and will modify the return value according to the return value of the child node |

| Name | Description |
| ----------------- | ------------------------------------------------------------------------- |
| evaluateOnRunning | true : evaluate the condition if the previous status is `Status.Running`. |

## Built In Composite Node

Expand Down Expand Up @@ -138,7 +119,11 @@ public class Wait : Action
* Override `OnAwake` called by `AkiBT.BehaviorTree.Awake` if needed.
* Override `OnStart` called by `AkiBT.BehaviorTree.Start` if needed.
* Conditional Node has `gameObject` field with `AkiBT.BehaviorTree` attached.
* Private [SerializeField] field and public field can be set on Behavior Tree editor window.
* Private `[SerializeField]` field and public field can be set on Behavior Tree editor window.

| Name | Description |
| ----------------- | ------------------------------------------------------------------------- |
| evaluateOnRunning | true : evaluate the condition if the previous status is `Status.Running`. |

```c#
public class IsHateGt: Conditional
Expand Down Expand Up @@ -329,16 +314,17 @@ public class SetFloat : Action
}
```

## Runtime Build BehaviorTree
## BehaviorTree Builder

Use `BehaviorTreeBuilder` to build a behaviorTree on the builder pattern.

Use `BeginChild` to start writing child or children.

Use `EndChild` to end writing.

Example:
Use `New{VariableType}` to get a reference of SharedVariable, if not exist before, it will create new one.
```C#
// Example code
var builder = new BehaviorTreeBuilder(gameObject);
//Create and set value of local variable
builder.NewObject<NavMeshAgent>("NavAgent",navmeshAgent);
Expand Down Expand Up @@ -411,64 +397,4 @@ Example:
| GetValue | Get variable value |
| Bind | Bind to other sharedVariable |
| Unbind | Unbind self |
| Observe | Create a observe proxy variable |

## Editor Extend

### How to change font

For visual effects such as fonts, colors, layout, etc, you can change the uss style file in `BehaviorTreeSetting`.

### How to customize node

For many reason, you may want to customize node like adding a button to preview effect.

You can write an editor class to provide your node which is similar to customize `Editor` in `UnityEditor`.
```C#
[Ordered]
public class SampleResolver : INodeResolver
{
//Create custom node
public IBehaviorTreeNode CreateNodeInstance(Type type)
{
return new SampleNode();
}
//Identify node type
public static bool IsAcceptable(Type behaviorType) => behaviorType == typeof(SampleClass);

//Your custom node
private class SampleNode : ActionNode
{
}
}
```

### How to customize field

Since AkiBT use GraphView as frontend which is powered by UIElement, it can not support all fields.

If you want to customize field or want to support some fields AkiBT currently not support (eg. Array), you can write an editor class to provide your field which is similar to customize `PropertyDrawer` in `UnityEditor`.

```C#
[Ordered]
public class LocalizedStringResolver : FieldResolver<LocalizedStringField,LocalizedString>
{
public LocalizedStringResolver(FieldInfo fieldInfo) : base(fieldInfo)
{
}
protected override LocalizedStringField CreateEditorField(FieldInfo fieldInfo)
{
return new LocalizedStringField(fieldInfo.Name);
}
public static bool IsAcceptable(Type infoType, FieldInfo _) => infoType == typeof(LocalizedString);

}
public class LocalizedStringField : BaseField<LocalizedString>
{

}
```

### How to use IMGUI in Graph Editor

If you don't want to use ui element, you can notify the field with `WarpFieldAttribute` to let editor use IMGUI as field's frontend.
| Observe | Create an observe proxy variable |
File renamed without changes.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ This part will explain the advanced skills and knowledge related to using AkiBT

<img src="./Docs/Images/ReferenceVariable.png" />

* SharedObject supports type restrictions, see [SharedVariable](./API.md#SharedVariable) for details
* SharedObject supports type restrictions, see [SharedVariable](./Docs/runtime-extensions.md#SharedVariable) for details

* Double-click the shared variable to modify the name, delete it if it is empty, and update the node field that references the variable after modification.

Expand Down Expand Up @@ -161,11 +161,11 @@ Different scopes can depend on each other. For example, ``SceneVariableScope`` c

## Extend Node

***See [API Document](./API.md)***
***See [Runtime Extensions](./Docs/runtime-extensions.md)***

## Extend Editor

***See [API Document](./API.md)***
***See [Editor Extensions](./Docs/editor-extensions.md)***


## DSL
Expand Down
8 changes: 4 additions & 4 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# 行为树 AkiBT Version 1.4.3

***Read this document in English: [English Document](./README_EN.md)***
***Read this document in English: [English Document](./README.md)***

AkiBT是以[UniBT](https://github.com/yoshidan/UniBT)作为基础的行为树结点编辑器, UniBT原作者为[Yoshida](https://github.com/yoshidan/),在前者基础上丰富了大量现代行为树编辑器功能.

Expand Down Expand Up @@ -84,7 +84,7 @@ AkiBT是以[UniBT](https://github.com/yoshidan/UniBT)作为基础的行为树结

<img src="./Docs/Images/ReferenceVariable.png" />

* SharedObject支持进行类型限制,详见[SharedVariable](./API.md#SharedVariable)
* SharedObject支持进行类型限制,详见[SharedVariable](./runtime-extensions.md#SharedVariable)

* 双击共享变量以修改名称,为空时删除,修改后同时更新引用该变量的结点字段

Expand Down Expand Up @@ -162,11 +162,11 @@ AkiBT是以[UniBT](https://github.com/yoshidan/UniBT)作为基础的行为树结

## 如何拓展结点

***查看 [API文档](./API.md)***
***查看 [运行时拓展](./Docs/runtime-extensions.md)***

## 如何拓展编辑器

***查看 [API文档](./API.md)***
***查看 [编辑器拓展](./Docs/editor-extensions.md)***

## 拓展功能 Extra Module

Expand Down

0 comments on commit 5e49e0d

Please sign in to comment.