ToolbarItem attribute
Instruction to create custom item in tracker window toolbars.
In the AI Tree you can easily modify editor windows by using scripting API. In this page we will show how add custom button to behaviour tree window toolbar.
We will show you an example of a function that will collect all the necessary windows. Let's move the Auto Layout function to the behaviour tree window itself.
Keep in mind that the following code uses editor assemblies and dependencies, if you use them in a runtime build, do not forget to wrap this sections of code with a UNITY_EDITOR
define.
Create a static method in any of your scripts, it can be any class and add [ToolbarItem] attribute.
Let's look at each line in more detail.
"Auto Layout" - name of item.
typeof(BehaviourTreeWindow) - the type of toolbar window that we are modifying.
ToolbarItemLayout.Right - layout side where you want to add item.
Method must be static, with/without any of access modifiers and with void
return type.
Get the first available behaviour tree window if there is one, otherwise create new one.
Automatically create new missing tools and dock to previously finded ot created behaviour tree window.
Full method one more time and result
Keep in mind that shown above is only used as an example. For example, it may incorrectly handle cases when multiple behaviour tree windows are open. Since GetOrCreateTracker
returns the first window from the set, it does not guarantee focus.
For this cases you can use following code.
Last updated