Custom Inspector for multiple scripts

So as the title says I have bunch scripts used just for different variations of enemies, I want to add some custom editor buttons to all the variations. Is there a way to group them together. How would I go about do something like that.

You can make your scripts inherit from a base class (that inherits from MonoBehaviour). After that you can write a custom editor for the base class and custom editors for the derived classes that inherit from the base editor too. If you call the base OnInspectorGUI method from the derived editors you can draw buttons on the base editor.

Anyway, I don’t think that inheriting custom editors is a good practice. I wrote a quick test and simple stuff worked, but I can imagine some problems already:

  • The “OnEnable” function used to initialize the editor variables is private, so derived editors can’t call base.OnEnable() for correct initialization. A workaround would be to add a protected method for initialization, and call it from OnEnable in the derived classes.

  • If the base class has some fields shown in the inspector, the derived classes will have that too. It shows only one entry for that field even if both base and derived default inspector are drawn, but the order is weird. I added a float field to the base class and a button in it’s custom editor, then an int in the derived class and a helpbox. The inspector ended up with the float field first (base), the int field second (derived), the button (base) and the helpbox (derived).