Game Development Reference
In-Depth Information
LoadedPlayer =
SerializerHelper.DeSerialise<PlayerSaveState>
(playerSerializedState);
#else
//Get the file
using (var stream = File.Open(saveFilePath,
FileMode.Open))
{
LoadedPlayer =
SerializerHelper.DeSerialise<PlayerSaveState>
(stream);
}
#endif
currentPlayer =
LoadedPlayer.LoadPlayerSaveState(currentPlayer);
}
}
catch
{
Debug.LogError("Loading data failed, file is
corrupt");
}
LoadComplete();
}
Additionally, since the File class on Windows 8 only returns a byte array ( byte[] ), we
need another deserialize function to work with the byte arrays instead of a stream.
So, open the SerializationHelper script and add the following method:
public static T DeSerialise<T>(byte[] input)
{
T output = default(T);
//Create an XML formatter
var serializer = new XmlSerializer(typeof(T));
try
{
//Create an in-memory stream with the serialsed data in
it
using (var stream = new MemoryStream(input))
Search WWH ::




Custom Search