Documentation

Learn how to use NodeCanvas

Download PDF Version

1.Creating Custom Object Drawers

Custom Object and Attribute Drawers work very similar to Unity’s Property Drawers feature and with it, it is possible to customize how a certain object (class/structure) appears in all NodeCanvas inspectors, as well as create GUI for custom attributes.

Object Drawers

Let’s suppose we have this example struct (it could also be a class of course).

To create a custom drawer for this object, you simply need to create a class and derive from the generic version of ObjectDrawer, the implement the OnGUI method. For example:

The instance parameter of the OnGUI method above, is always of type T. By the end of the OnGUI method you must return the modified instance.

That’s it. The drawer will work exactly the same for field of BBParameter<MyExampleStruct> as well. Both are shown bellow.

ObjectDrawer

Attribute Drawers

For this example, we are going to re-create a Range(min, max) attribute. So, let’s first create the attribute, with the only requirement being that it has to derive from CustomDrawerAttribute.

Then to create the actual GUI drawer for this attribute, in short, you need to create a class and derive from the generic version of AttributeDrawer. Much similar on how it was done before for ObjectDrawer. In this case, the T argument, represents the type of the attribute we need to create the drawer for.

The instance here is always of type object. The inherited ‘attribute’ property returns our attribute which we can use to fetch it’s meta data. No casting required here since out attribute is of type T.

Finally, we simply add this new attribute above a float, or even a BBParameter<float>. It will work exactly the same. Both are shown bellow.

AttributeDrawer

Was this helpful? Yes No Suggest edit
Suggest Edit