Question by
shadow_bird · Oct 25, 2017 at 03:40 PM ·
editor-scriptingpropertydrawer
PropertyDrawer with child class
Hi,
(The context is below)
I have an issue when I have a list of items with a type of a parent class (polymorphism). I want the PropertyDrawer from children class to be called but it's always the parent associated PropertyDrawer that is called (ClassAPropertyDrawer).
Even though in the OnGUI function the serializedProperty has an objectReferenceValue with the child type but a type of the parent...
I did tried to set true to "includeChildren" when calling the display function (but no changes)
EditorGUI.PropertyField(rect, itemList, true);
Code context :
public abstract class ClassA : MonoBehaviour
{
}
public class ClassB : ClassA
{
}
public class ClassC : ClassA
{
}
public class Container : MonoBehaviour
{
[SerializeField]
public List<ClassA> list;
}
[CustomPropertyDrawer(typeof(ClassA))]
public class ClassAPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
}
}
[CustomPropertyDrawer(typeof(ClassB))]
public class ClassBPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
}
}
[CustomPropertyDrawer(typeof(ClassC))]
public class ClassCPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
}
}
Thanks for the help !
Comment