case 254: // Serialization using Reflection
{
#if REFLECTION_SUPPORT
// Create the object
if (obj == null)
{
obj = type.Create();
if (obj == null) Debug.LogError("Unable to create an instance of " + type);
}
if (obj != null)
{
// How many fields have been serialized?
int count = ReadInt(reader);
for (int i = 0; i < count; ++i)
{
// Read the name of the field
string fieldName = reader.ReadString();
if (string.IsNullOrEmpty(fieldName))
{
Debug.LogError("Null field specified when serializing " + type);
continue;
}
// Try to find this field
FieldInfo fi = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
// Read the value
object val = reader.ReadObject();
// Assign the value
if (fi != null) fi.SetValue(obj, Serialization.ConvertValue(val, fi.FieldType));
else Debug.LogError("Unable to set field " + type + "." + fieldName);
}
}
#else
Debug.LogError("Reflection is not supported on this platform");
#endif
return obj;
}