Extending A Base Class
For most drawer that represent class members, you have to base classes you can inherit from that implement the IFieldDrawer interface.
For simple class members that don’t have any member drawers and consist only of a prefix label and a single control, you can derive from PrefixControlComboDrawer.
For more complex class members that have one or more member drawers, you can derive from ParentFieldDrawer.
For Power Inspector to know which elements inside the inspector should be handled by your drawer, you’ll need to add the DrawerForField attribute to the class.
Here is an example of the attribute being used:
/// <summary> /// Draws a toggle control which can be backed by a boolean field or property. /// </summary> [Serializable, DrawerForField(typeof(bool))] public class ToggleDrawer : PrefixControlComboDrawer<bool>
When Power Inspector prepares a drawer for use inside an Inspector, it will call two methods inside the drawer class:
- First, it will call the SetupInterface method (as defined in the IFieldDrawer interface).
- After that has finished, it will call the LateSetup method (as defined in the base IDrawer interface).
All drawer class also contain a Setup method. The only job of the SetupInterface method is to take the parameters provided by Power Inspector, and to convert them into a form that the main Setup method can accept, and then call that Setup method.
You can override the Setup and LateSetup methods if you want to customize the setup phase.
IMPORTANT: If you override Setup or LateSetup, remember to always also call base.Setup and base.LateSetup!
When extending the ParentFieldDrawer, you can override the DoGenerateMemberBuildList method to gain control over which members to include inside the drawer. This is done through deciding which LinkedMemberInfos are placed inside the memberBuildList.
You can also override DoBuildMembers of ParentFieldDrawer to customize exactly how member drawers are built from the memberBuildList that was previously generated by the DoGenerateMemberBuildList method.
During the execution of this method all member drawers should be created and placed into the members array.
You can use ParentDrawerUtility.BuildMembers to automatically generate members based on the contents of the memberBuildList.