Hi, I have written a PropertyDrawer for an custom class. For this class I have several Defaults (like Vector3 has up, right,…) The PropertyDrawer shows a Popuplist of all those defaults.
object targetObj = fieldInfo.GetValue(prop.serializedObject.targetObject);
MyClass target = targetObj as MyClass;
//find index in defaults list
//show popup
//if changed -> apply
target = MyClass.GetDefault(selectedIndex);
This works like a charm if there is a single MyClass Object. When there is an array of MyClass the targetObj becomes an array too.
[SerializeField] MyClass test = new MyClass(); //works
[SerializeField] MyClass[] test2; //Elements are not initialized when size is set in inspector
[SerializeField] MyClass[] test3 = { //only access to whole array
new MyClass(),
new MyClass(),
new MyClass()
};
So why is that?
Is there a way to determine the actual Element’s index? (targetObj can be cast to MyClass )
Or is there a simpler way I don’t know of?