public object Deserialize([NotNull] MonoBehaviour monoBehavior, [NotNull] Type type) { if (monoBehavior == null) { throw new ArgumentNullException(nameof(monoBehavior)); } var typeNodes = monoBehavior.serializedType.m_Nodes; // Types nodes are empty, which means null if (typeNodes == null) { return(SerializingHelper.CreateDefaultOf(type)); } // We should actually read the contents and deserialize an object var structure = StructureReader.ReadMembers(typeNodes, monoBehavior.reader); Debug.Assert(structure.Length == 1); var rootObject = structure[0].Value; Debug.Assert(rootObject != null); Debug.Assert(rootObject is CustomType); var serializer = _context.Value.GetSerializerOf(type); var obj = serializer.DeserializeObject((CustomType)rootObject, 0); return(obj); }
public object Deserialize([NotNull] MonoBehaviour monoBehavior, [NotNull] Type type) { if (monoBehavior == null) { throw new ArgumentNullException(nameof(monoBehavior)); } var typeNodes = monoBehavior.serializedType.m_Nodes; if (typeNodes == null) { return(CreateDefaultOf(type)); } else { var structure = StructureReader.ReadMembers(typeNodes, monoBehavior.reader); Debug.Assert(structure.Count == 1); var structureValues = structure.Values.ToArray(); var rootObject = structureValues[0]; Debug.Assert(rootObject != null); Debug.Assert(rootObject is CustomType); var obj = DeserializeObject(type, (CustomType)rootObject, 0); return(obj); } }