Forums › 💬 NodeCanvas › ⚙️ Support › Custom ReflectedFieldInspector types › Reply To: Custom ReflectedFieldInspector types
Hello,
To avoid hacking the source code, the proper way is to [Create Custom Object Drawers].
Please take a look at the [Documentation for Creating Custom Object Drawers], but in short, you simply need to create a class like the following (remember that this is a Unity Editor only functionality, thus to wrap it into an #if UNITY_EDITOR define).
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#if UNITY_EDITOR using ParadoxNotion.Design; using UnityEngine; using UnityEditor; public class MyCustomClassDrawer : ObjectDrawer<MyCustomClass>{ public override MyCustomClass OnGUI(GUIContent content, MyCustomClass instance){ //Draw your GUI here, or call another method that does so. //Then return the instance. //For example: GUILayout.Label(content); return instance; } } #endif |
ObjectDrawer class also has some important inherited properties that you might want to use:
|
1 2 3 4 5 6 7 8 |
///The reflected FieldInfo representation protected FieldInfo fieldInfo{get; private set;} ///The parent object the instance is drawn within protected object context{get; private set;} ///The set of Drawer Attributes found on field protected DrawerAttribute[] attributes{get; private set;} |
Thus, if in your case, you already have created GUI Editors for your classes (like for example ActionFlowField), you could do something like this:
|
1 2 3 4 5 6 7 |
public class ActionFlowFieldDrawer : ObjectDrawer<ActionFlow>{ public override ActionFlow OnGUI(GUIContent content, ActionFlow instance){ return ActionFlowField(content, instance, context, fieldInfo); } } |
Or, you could move the code from your ActionFlowField method, into the OnGUI method of the ActionFlowFieldDrawer class, if it is only used within the context of NodeCanvas.
Please let me know if that works for you.
Thanks!
