- Home /
Custom inheritance classes and custom inspectors
Hi all,
my question is easier to understand than it is to explain.
I basically have two classes
public class myfirstclass : MonoBehaviour {
public SortedList<int, transform> mylist;
}
public class mysecondclass : myfirstclass {
Transform mytransform;
}
Now, I have a custom editor for myfirstclass:
[CustomEditor (typeof(myfirstclass))]
public class myfirstclass: Editor {
private myfirstclass element;
void Awake () {
element = (myfirstclass)target;
}
public override void OnInspectorGUI() {
EditorGUILayout.LabelField("wdf");
DrawDefaultInspector();
}
}
This basically works whenever I drag myfirstclass in any gameobject, but If I assign mysecondclass to a gameobject, the custom editor part is not drawn for it, and it'll just be presented as it would without editor. I am here hoping that we can in some way call a parent class editor class, like for example we do with the "base" keyword in the Awake function.
It'd sound very stupid and ridiculous if we had to completely rewrite an editor class completely disregarding inheritance.
Answer by .sanders · Jan 21, 2012 at 09:23 PM
Ok I am going to redirect you to basically the same question. I posted an answer there that will work in your case:
http://answers.unity3d.com/questions/51615/do-custom-inspectors-support-inheritance.html
I'll explain in short: your derived class should also have a CustomEditor script, otherwise unity will draw the default inspector. So if you have that and derive that CustomEditor script from your BaseClass's Editor script you can simply call it's OnInspectorGUI() from the OnInspectorGUI() of the derived CustomEditor. Note that will need to explicitly override the OnInspectorGUI(). I don't think it will work otherwise since it's just a sendMessage basically.
hope you can get it solved!
cheers!
Awesome. Your OnInspectorGUI call part was the missing link in my chain, thanks a lot.
I know this is old but thanks for the answer. Very effectively explained in a short paragraph.