Right now, the only information we have on the serialized property’s type is a field called propertyType. The problem is, it is an enum, not a real System.Type.
Is there a way to access the real System.Type of a SerializedProperty (or a SerializedObject for that matter) and be able to perform reflection on it?
public static Type GetActualType(this SerializedProperty prop)
{
switch (prop.propertyType) {
case SerializedPropertyType.Integer:
return typeof(int);
case SerializedPropertyType.Float:
return typeof(float);
case SerializedPropertyType.Boolean:
return typeof(bool);
case SerializedPropertyType.String:
return typeof(string);
case SerializedPropertyType.Color:
return typeof(Color);
case SerializedPropertyType.Bounds:
return typeof(Bounds);
case SerializedPropertyType.Rect:
return typeof(Rect);
case SerializedPropertyType.Vector2:
return typeof(Vector2);
case SerializedPropertyType.Vector3:
return typeof(Vector3);
case SerializedPropertyType.ObjectReference:
return prop.objectReferenceValue.GetType();
default: throw new Exception ("Invalid type: " + prop.propertyType.ToString());
}
}
// somewhere else...
var method = myProp.GetActualType().GetMethod(...);