Skip to content

Commit

Permalink
Merge pull request #3 from AkiKurisu/dev-1.4.4
Browse files Browse the repository at this point in the history
Merge dev
  • Loading branch information
AkiKurisu authored Jun 8, 2024
2 parents fe34111 + 77b7907 commit 7fee665
Show file tree
Hide file tree
Showing 251 changed files with 1,017 additions and 842 deletions.
8 changes: 8 additions & 0 deletions Docs.meta

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

File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
78 changes: 78 additions & 0 deletions Docs/editor-extensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<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. `UnityEngine.Localization.LocalizedString`), 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.

```C#
public class EventAction : Action
{
[WarpField]
public UnityEvent myEvent;
}
```

## How to customize graph editor

TODO
2 changes: 1 addition & 1 deletion README_EN.md.meta → 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 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.
26 changes: 26 additions & 0 deletions Editor/Core/Editor/BehaviorTreeDebugButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using UnityEngine;
using UnityEngine.UIElements;
namespace Kurisu.AkiBT.Editor
{
internal class BehaviorTreeDebugButton : Button
{
private const string ButtonText = "Edit BehaviorTree";
private const string DebugText = "Debug BehaviorTree";
public BehaviorTreeDebugButton(IBehaviorTree tree) : base(() => GraphEditorWindow.Show(tree))
{
style.fontSize = 15;
style.unityFontStyleAndWeight = FontStyle.Bold;
style.color = Color.white;
if (!Application.isPlaying)
{
style.backgroundColor = new StyleColor(new Color(140 / 255f, 160 / 255f, 250 / 255f));
text = ButtonText;
}
else
{
text = DebugText;
style.backgroundColor = new StyleColor(new Color(253 / 255f, 163 / 255f, 255 / 255f));
}
}
}
}
11 changes: 11 additions & 0 deletions Editor/Core/Editor/BehaviorTreeDebugButton.cs.meta

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

54 changes: 17 additions & 37 deletions Editor/Core/Editor/BehaviorTreeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ namespace Kurisu.AkiBT.Editor
[CustomEditor(typeof(BehaviorTree))]
public class BehaviorTreeEditor : UnityEditor.Editor
{
private const string LabelText = "AkiBT BehaviorTree <size=12>V1.4.3</size>";
private const string ButtonText = "Edit BehaviorTree";
private const string DebugText = "Debug BehaviorTree";
private IBehaviorTree Tree => target as IBehaviorTree;
private static readonly string LabelText = $"AkiBT BehaviorTree <size=12>{BehaviorTreeSetting.Version}</size>";
public override VisualElement CreateInspectorGUI()
{
var myInspector = new VisualElement();
var tree = target as IBehaviorTree;
var label = new Label(LabelText);
label.style.fontSize = 20;
label.style.unityTextAlign = TextAnchor.MiddleCenter;
Expand All @@ -25,58 +23,40 @@ public override VisualElement CreateInspectorGUI()
var field = new PropertyField(serializedObject.FindProperty("externalBehaviorTree"), "External BehaviorTree");
field.SetEnabled(!Application.isPlaying);
myInspector.Add(field);
if (Tree.SharedVariables.Count(x => x.IsExposed) != 0)
if (tree.SharedVariables.Count(x => x.IsExposed) != 0)
{
myInspector.Add(new SharedVariablesFoldout(Tree, target, this));
myInspector.Add(new SharedVariablesFoldout(tree, target, this));
}
var button = BehaviorTreeEditorUtility.GetButton(() => { GraphEditorWindow.Show(Tree); });
if (!Application.isPlaying)
{
button.style.backgroundColor = new StyleColor(new Color(140 / 255f, 160 / 255f, 250 / 255f));
button.text = ButtonText;
}
else
{
button.text = DebugText;
button.style.backgroundColor = new StyleColor(new Color(253 / 255f, 163 / 255f, 255 / 255f));
}
myInspector.Add(button);
myInspector.Add(new BehaviorTreeDebugButton(tree));
return myInspector;
}
}
[CustomEditor(typeof(BehaviorTreeSO))]
public class BehaviorTreeSOEditor : UnityEditor.Editor
{
private IBehaviorTree Tree => target as IBehaviorTree;
private const string LabelText = "AkiBT BehaviorTreeSO <size=12>V1.4.3</size>";
private const string ButtonText = "Edit BehaviorTreeSO";
private const string DebugText = "Debug BehaviorTreeSO";
private static readonly string LabelText = $"AkiBT BehaviorTreeSO <size=12>{BehaviorTreeSetting.Version}</size>";
public override VisualElement CreateInspectorGUI()
{
var myInspector = new VisualElement();
var tree = target as IBehaviorTree;
var label = new Label(LabelText);
label.style.fontSize = 20;
label.style.unityTextAlign = TextAnchor.MiddleCenter;
myInspector.Add(label);
myInspector.styleSheets.Add(BehaviorTreeSetting.GetInspectorStyle("AkiBT"));
var description = new PropertyField(serializedObject.FindProperty("Description"), string.Empty);
myInspector.Add(description);
if (Tree.SharedVariables.Count(x => x.IsExposed) != 0)
myInspector.Add(new Label("Editor Description"));
var description = new TextField(string.Empty)
{
myInspector.Add(new SharedVariablesFoldout(Tree, target, this));
}
var button = BehaviorTreeEditorUtility.GetButton(() => { GraphEditorWindow.Show(Tree); });
if (!Application.isPlaying)
{
button.style.backgroundColor = new StyleColor(new Color(140 / 255f, 160 / 255f, 250 / 255f));
button.text = ButtonText;
}
else
multiline = true
};
description.style.minHeight = 60;
description.BindProperty(serializedObject.FindProperty("description"));
myInspector.Add(description);
if (tree.SharedVariables.Count(x => x.IsExposed) != 0)
{
button.text = DebugText;
button.style.backgroundColor = new StyleColor(new Color(253 / 255f, 163 / 255f, 255 / 255f));
myInspector.Add(new SharedVariablesFoldout(tree, target, this));
}
myInspector.Add(button);
myInspector.Add(new BehaviorTreeDebugButton(tree));
return myInspector;
}
}
Expand Down
Loading

0 comments on commit 7fee665

Please sign in to comment.