- Home /
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.
Answer by DiegoSLTS · Aug 15, 2016 at 09:09 PM
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).
Your answer
Follow this Question
Related Questions
Custom inspector adding scripts 1 Answer
How to disable a collision box with a keyboard key 2 Answers
Mouse Position turning 3rd person space sim. 0 Answers
Precomputed Realtime GI, while playing 1 Answer
Interactive 2D Foliage 0 Answers