Hi guys.
I have 2 classes: the base class (which is abstract) and the derived one.
I also made 2 different editor scripts: one for the base and one for the derived.
Of course, the editor script for the derived class is derived from the editor script of the editor script of the base class (I think you lost me now…).
Basically I have something like:
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(AbstractBaseClass))]
public class AbstractBaseClassEditor : Editor {
protected SerializedObject InspectorObjects;
protected SerializedProperty InspectorObjectsIterator;
void OnEnable() {
InspectorObjects = new SerializedObject(target);
}
public override void OnInspectorGUI() {
InspectorObjectsIterator = InspectorObjects.GetIterator();
AbstractBaseClass abstractBaseClass = (AbstractBaseClass)target;
EditorGUILayout.BeginVertical(); {
bool next = InspectorObjectsIterator.NextVisible(true);
while (next) {
// do all I need to show the class as I want....
if (next) {
EditorGUILayout.PropertyField(InspectorObjectsIterator);
next = InspectorObjectsIterator.NextVisible(true);
}
}
} EditorGUILayout.EndVertical();
InspectorObjects.ApplyModifiedProperties();
}
}
and
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(DerivedClass), true)]
public class DerivedClassEditor : AbstractBaseClassEditor {
public override void OnInspectorGUI() {
base.OnInspectorGUI();
InspectorObjectsIterator = InspectorObjects.GetIterator();
DerivedClass derivedClass = (DerivedClass)target;
EditorGUILayout.BeginVertical(); {
bool next = InspectorObjectsIterator.NextVisible(true);
while (next) {
// do all I need to do with the additional derived class fields.
if (next) {
EditorGUILayout.PropertyField(InspectorObjectsIterator);
next = InspectorObjectsIterator.NextVisible(true);
}
}
} EditorGUILayout.EndVertical();
InspectorObjects.ApplyModifiedProperties();
}
}
Basically if I do this, in the inspector, I will have all the fields of both classes twice: the first time formatted as defined in the abstract base class editor script (so the base class fields formatted correctly and the derived class fields not formatted at all) and the second time as defined in the derived class editor script (so the base class fields not formatted at all and the derived class fields correctly formatted).
I’ve experimented a lot of combinations but I was not able to reproduce the wanted effect.
I’ve also checked on the forum but all the solutions proposed in the previous threads are not working for me and on top of that I really cannot see what I’m doing differently.
Can someone point me in the right direction?
Thanks