Extending the editor - Zelgunn/Unity3DTools GitHub Wiki
Extending the editor
Table of contents
How to create a custom node
When you first open the editor, your node browser will look like that:
You can simply add one of your methods to this browser by adding the [TriggersEditor.NodeMethod] attribute to it:
Methods with this attribute must be public.
There are 3 mandatory parameters and 1 optional for this attribute. The first parameter is the category of the node, the second is the name of the node and the third is the type of the node. Note that:
- Events (NodeMethodType.Event) output a bool
- Conditions (NodeMethodType.Condition) output a bool
- Actions (NodeMethodType.Action) either output nothing (void) or a IEnumerator (used in coroutines, for methods such as Wait).
- Others (NodeMethodType.Other) should always output at least one value (otherwise, the node won't be very useful).
With the above code, you obtain this result:
How to create a custom category
As you can see in above illustration, a new category appeared and it uses the default icon (the wheel). You can create a category by just creating a node with this category, here I created the category "Example".
You may have noticed that other categories have custom icons, that are displayed in different places in the editor. You can also add custom icons to your own categories, by creating a "Node category" asset in your project:
The name of the asset must be the same as the one used in your code:
Once the category asset created, select it and give it an icon:
Your category will look like that (here I used the Knob sprite from Unity):
Note that the editor only updates icons after an assembly reload or when you open Unity.
Subcategories
You can create subcategories, using '/' between layers. For example : "Category/SubCategory1/SubCategory2". This will create subcategories in the node browser. Since you can't put '/' in the name of the category asset, just use the last subcategory. The name of the category asset for "Category/SubCategory1/SubCategory2" is "SubCategory2".
Custom node advanced options
Methods used for nodes have to be declared public, can either be static or non-static, return something or not, and use the "out" keyword to output more values.
Here are three more examples of nodes:
- Non-static method
- Method with a return type
- Method using the "out" keyword
Input/Output names
- Input - object of the method: Always named "Object"
- Input - parameters: Uses the name of the parameter in your code. It uses the same parsing as Unity: spaces are inserted before each capital letter and the first letter is always a capital letter
- Output - return value: Defined by the 4th parameter of the NodeMethod attribute.
- Output - "out" parameters: Same as Input - parameters.