Game Development Reference
In-Depth Information
var playerSerializedState =
SerializerHelper.Serialise<PlayerSaveState>
(currentPlayer.GetPlayerSaveState());
#if UNITY_METRO
UnityEngine.Windows.File.WriteAllBytes(saveFilePath,
playerSerializedState);
#else
using (var file = File.Create(saveFilePath))
{
file.Write(playerSerializedState, 0,
playerSerializedState.Length);
}
#endif
}
catch
{
Debug.LogError("Saving data failed");
}
}
In the preceding code, we have added a preprocessor directive for the
UNITY_METRO
target (and moved up the
playerSerializedState
variable as it can be used by all
platforms).
Now when you build for Windows 8, it will use the first block of code. For all other plat-
forms, it will use the second block.
We have to perform something similar for the
LoadState
class as follows:
public static void LoadState(Action LoadComplete)
{
PlayerSaveState LoadedPlayer;
try
{
if (SaveAvailable)
{
#if UNITY_METRO
var playerSerializedState =
UnityEngine.Windows.File.ReadAllBytes(saveFilePath);