public override void Deserialize(IOReader reader) { base.Deserialize(reader); // Read tile positions. TileX = reader.ReadInt32(); TileY = reader.ReadInt32(); TileZ = reader.ReadInt32(); }
public void DeserializeAllNew(IOReader reader) { ClearEntities(); // Read name map... Type[] blankParams = new Type[0]; object[] blankArgs = new object[0]; int count = reader.ReadInt32(); Type[] types = new Type[count]; ConstructorInfo[] constructors = new ConstructorInfo[count]; for (int i = 0; i < count; i++) { string typeName = reader.ReadString(); Type t = Type.GetType(typeName, false, false); if (t == null) { throw new Exception($"Entity of type {typeName} could not be found, so cannot be loaded from disk! Reading cannot continue because data length is unknown."); } var constructor = t.GetConstructor(blankParams); if (constructor == null) { throw new Exception($"Entity of type {typeName} does not have a no-parameter constructor, so cannot be loaded. Reading cannot continue since data length is unknown."); } types[i] = t; constructors[i] = constructor; } count = reader.ReadInt32(); for (int i = 0; i < count; i++) { ushort typeMapIndex = reader.ReadUInt16(); var constructor = constructors[typeMapIndex]; var obj = constructor.Invoke(blankArgs); // No need to register: Entities should auto register, especially since the default constructor is being used. Entity e = obj as Entity; e.Deserialize(reader); } }