//******************************************************************************************** // //******************************************************************************************** public static bool SerializeMembers(T instance, Stream stream) { if (m_formatter == null) { return(false); } if (instance == null) { return(false); } if (stream == null) { return(false); } Debug.Log("Serializing: " + instance.ToString()); SERIALIZATION.Manifest <T> manifest = new SERIALIZATION.Manifest <T>(instance); if (manifest.Serialize(stream, m_formatter) == false) { return(false); } for (int entry = 0; entry < manifest.m_entries.Count; ++entry) { System.Reflection.FieldInfo fieldinfo = manifest.m_entries[entry].fieldinfo; object value = fieldinfo != null?fieldinfo.GetValue(instance) : null; Debug.Log("Serializing field: " + fieldinfo.Name + " value: " + ((value != null) ? value.ToString() : "null")); m_formatter.Serialize(stream, value); } return(true); }
//******************************************************************************************** // //******************************************************************************************** public static bool DeserializeMembers(T instance, Stream stream) { if (m_formatter == null) { return(false); } if (instance == null) { return(false); } if (stream == null) { return(false); } Debug.Log("Deserializing: " + instance.ToString()); SERIALIZATION.Manifest <T> manifest = new SERIALIZATION.Manifest <T>(stream, m_formatter); for (int field = 0; field < manifest.m_entries.Count; ++field) { System.Reflection.FieldInfo fieldinfo = manifest.m_entries[field].fieldinfo; object val = m_formatter.Deserialize(stream); if (fieldinfo != null) { fieldinfo.SetValue(instance, val); Debug.Log("Deserialized field: " + fieldinfo.Name + " value: " + ((val != null) ? val.ToString() : "null")); } } return(true); }