Skip to content

Commit

Permalink
Duplicate node serialized data to recover class missing
Browse files Browse the repository at this point in the history
  • Loading branch information
AkiKurisu committed Jul 13, 2024
1 parent ef62963 commit f96875b
Show file tree
Hide file tree
Showing 23 changed files with 190 additions and 213 deletions.
Binary file removed Docs/Images/External.png
Binary file not shown.
96 changes: 0 additions & 96 deletions Docs/Images/External.png.meta

This file was deleted.

Binary file added Docs/Images/MissingClass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 13 additions & 8 deletions Docs/Images/OpenSO.png.meta → Docs/Images/MissingClass.png.meta

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

Binary file removed Docs/Images/OpenSO.png
Binary file not shown.
Binary file modified Docs/Images/started1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 24 additions & 1 deletion Docs/editor-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,27 @@ public class EventAction : Action

## How to customize graph editor

TODO
TODO

## Use stack node style (experimental)

Connecting Composite nodes to child nodes may be troublesome, especially when reordering. You can use Composite Stack to replace the traditional node style. There is no node using this style in the built-in nodes. If you need to use it, you need to write a ``NodeResolver`` to declare the nodes used, the example is as follows:
```C#
using System;
namespace Kurisu.AkiBT.Editor
{
[Ordered]
public class SequenceResolver : INodeResolver
{
public IBehaviorTreeNode CreateNodeInstance(Type type)
{
return new SequenceStack();
}
public static bool IsAcceptable(Type behaviorType) => behaviorType == typeof(Sequence);
}
public class SequenceStack : CompositeStack { }
}

```
<img src="./Images/CompositeStack.gif"/>
Of course, this feature currently has some limitations, such as the inability to nest Composite Stack.
4 changes: 2 additions & 2 deletions Editor/Core/Editor/BehaviorTreeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override VisualElement CreateInspectorGUI()
label.style.fontSize = 20;
label.style.unityTextAlign = TextAnchor.MiddleCenter;
myInspector.Add(label);
myInspector.styleSheets.Add(BehaviorTreeSetting.GetInspectorStyle("AkiBT"));
myInspector.styleSheets.Add(BehaviorTreeSetting.GetOrCreateSettings().GetInspectorStyle("AkiBT"));
var toggle = new PropertyField(serializedObject.FindProperty("updateType"), "Update Type");
myInspector.Add(toggle);
var field = new PropertyField(serializedObject.FindProperty("externalBehaviorTree"), "External BehaviorTree");
Expand Down Expand Up @@ -51,7 +51,7 @@ public override VisualElement CreateInspectorGUI()
label.style.fontSize = 20;
label.style.unityTextAlign = TextAnchor.MiddleCenter;
myInspector.Add(label);
myInspector.styleSheets.Add(BehaviorTreeSetting.GetInspectorStyle("AkiBT"));
myInspector.styleSheets.Add(BehaviorTreeSetting.GetOrCreateSettings().GetInspectorStyle("AkiBT"));
myInspector.Add(new Label("Editor Description"));
var description = new TextField(string.Empty)
{
Expand Down
8 changes: 5 additions & 3 deletions Editor/Core/GraphView/BehaviorTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ public class BehaviorTreeView : GraphView, ITreeView, ILayoutTreeNode
private readonly BehaviorNodeConvertor converter = new();
VisualElement ILayoutTreeNode.View => this;
public GraphView View => this;
private readonly BehaviorTreeSetting setting;
public BehaviorTreeView(IBehaviorTreeContainer container, EditorWindow editor)
{
EditorWindow = editor;
Container = container;
Instance = container.GetBehaviorTree();
Assert.IsNotNull(Instance.root);
setting = BehaviorTreeSetting.GetOrCreateSettings();
LocalConstruct();
}
/// <summary>
Expand All @@ -45,14 +47,14 @@ private void SetStyle()
{
style.flexGrow = 1;
style.flexShrink = 1;
styleSheets.Add(BehaviorTreeSetting.GetGraphStyle(EditorName));
styleSheets.Add(setting.GetGraphStyle(EditorName));
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
Insert(0, new GridBackground());
}
private void AddNodeProvider()
{
var provider = ScriptableObject.CreateInstance<NodeSearchWindowProvider>();
provider.Initialize(this, BehaviorTreeSetting.GetMask(EditorName));
provider.Initialize(this, setting.GetMask(EditorName));
nodeCreationRequest += context =>
{
SearchWindow.Open(new SearchWindowContext(context.screenMousePosition), provider);
Expand Down Expand Up @@ -168,7 +170,7 @@ public void CopyFromTree(BehaviorTree tree, Vector2 mousePosition)
/// <returns></returns>
public string SerializeTreeToJson()
{
return BehaviorTree.Serialize(Instance, false, true);
return BehaviorTree.Serialize(Instance, false, setting.JsonSerializeEditorData);
}
/// <summary>
/// Copy BehaviorTree from json file
Expand Down
15 changes: 7 additions & 8 deletions Editor/Core/GraphView/Member/StringResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@
using UnityEngine.UIElements;
namespace Kurisu.AkiBT.Editor
{
public class StringResolver : FieldResolver<TextField,string>
public class StringResolver : FieldResolver<TextField, string>
{
private bool multiline;
public StringResolver(FieldInfo fieldInfo) : base(fieldInfo)
{
multiline=fieldInfo.GetCustomAttribute<MultilineAttribute>()!=null;
}

protected override TextField CreateEditorField(FieldInfo fieldInfo)
{
var field = new TextField(fieldInfo.Name);
field.style.minWidth = 200;
if(multiline)
if (fieldInfo.GetCustomAttribute<MultilineAttribute>() != null)
{
field.multiline=true;
field.style.maxWidth=250;
field.style.whiteSpace=WhiteSpace.Normal;
field.multiline = true;
field.style.maxWidth = 250;
field.style.whiteSpace = WhiteSpace.Normal;
}
return field;
}
public static bool IsAcceptable(Type infoType,FieldInfo info)=>infoType == typeof(string);
public static bool IsAcceptable(Type infoType, FieldInfo _) => infoType == typeof(string);
}
}
2 changes: 1 addition & 1 deletion Editor/Core/GraphView/Node/ActionNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
evt.menu.MenuItems().Add(new BehaviorTreeDropdownMenuAction("Change Behavior", (a) =>
{
var provider = ScriptableObject.CreateInstance<ActionSearchWindowProvider>();
provider.Init(this, BehaviorTreeSetting.GetMask(MapTreeView.EditorName));
provider.Init(this, BehaviorTreeSetting.GetOrCreateSettings().GetMask(MapTreeView.EditorName));
SearchWindow.Open(new SearchWindowContext(a.eventInfo.localMousePosition), provider);
}));
base.BuildContextualMenu(evt);
Expand Down
2 changes: 1 addition & 1 deletion Editor/Core/GraphView/Node/CompositeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
evt.menu.MenuItems().Add(new BehaviorTreeDropdownMenuAction("Change Behavior", (a) =>
{
var provider = ScriptableObject.CreateInstance<CompositeSearchWindowProvider>();
provider.Init(this, BehaviorTreeSetting.GetMask(MapTreeView.EditorName));
provider.Init(this, BehaviorTreeSetting.GetOrCreateSettings().GetMask(MapTreeView.EditorName));
SearchWindow.Open(new SearchWindowContext(a.eventInfo.localMousePosition), provider);
}));
evt.menu.MenuItems().Add(new BehaviorTreeDropdownMenuAction("Add Child", (a) => AddChild()));
Expand Down
2 changes: 1 addition & 1 deletion Editor/Core/GraphView/Node/ConditionalNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
evt.menu.MenuItems().Add(new BehaviorTreeDropdownMenuAction("Change Behavior", (a) =>
{
var provider = ScriptableObject.CreateInstance<ConditionalSearchWindowProvider>();
provider.Init(this, BehaviorTreeSetting.GetMask(MapTreeView.EditorName));
provider.Init(this, BehaviorTreeSetting.GetOrCreateSettings().GetMask(MapTreeView.EditorName));
SearchWindow.Open(new SearchWindowContext(a.eventInfo.localMousePosition), provider);
}));
base.BuildContextualMenu(evt);
Expand Down
2 changes: 1 addition & 1 deletion Editor/Core/GraphView/Node/DecoratorNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
evt.menu.MenuItems().Add(new BehaviorTreeDropdownMenuAction("Change Behavior", (a) =>
{
var provider = ScriptableObject.CreateInstance<DecoratorSearchWindowProvider>();
provider.Init(this, BehaviorTreeSetting.GetMask(MapTreeView.EditorName));
provider.Init(this, BehaviorTreeSetting.GetOrCreateSettings().GetMask(MapTreeView.EditorName));
SearchWindow.Open(new SearchWindowContext(a.eventInfo.localMousePosition), provider);
}));
base.BuildContextualMenu(evt);
Expand Down
2 changes: 1 addition & 1 deletion Editor/Core/GraphView/Node/Factory/NodeResolverFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public IBehaviorTreeNode Create(Type behaviorType, ITreeView treeView)
}
if (!find) node = new ActionNode();
node.SetBehavior(behaviorType, treeView);
if (styleSheetCache == null) styleSheetCache = BehaviorTreeSetting.GetNodeStyle(treeView.EditorName);
if (styleSheetCache == null) styleSheetCache = BehaviorTreeSetting.GetOrCreateSettings().GetNodeStyle(treeView.EditorName);
node.View.styleSheets.Add(styleSheetCache);
return node;
}
Expand Down
Loading

0 comments on commit f96875b

Please sign in to comment.