private static void OnSavedGameDataRead(SavedGameRequestStatus status, byte[] data) { //Debug.Log("DoneLoading GP: " +status); if (status == SavedGameRequestStatus.Success) { // handle processing the byte array data loadedData = ObjectSerializationExtension.Deserialize <PlayerData>(data); } else { // handle error } }
void RestoreGame() { WorldSave save = new WorldSave(); if (System.IO.File.Exists("data.dat")) { byte[] data = File.ReadAllBytes("data.dat"); Debug.Log(data.Length); if (data.Length > 0) { save = ObjectSerializationExtension.Deserialize <WorldSave>(data); int index = 0; for (int i = 0; i < VoxelData.m_WorldSizeInChunks; ++i) { for (int j = 0; j < VoxelData.m_WorldSizeInChunks; ++j) { if (save.m_Chunks[index] != null) { if (m_World.m_Chunks[i, j] == null) { m_World.m_Chunks[i, j] = new Chunk(save.m_Chunks[index].m_Coord, m_World, true); } int voxelIndex = 0; for (int k = 0; k < VoxelData.m_ChunkWidth; ++k) { for (int d = 0; d < VoxelData.m_ChunkHeight; ++d) { for (int c = 0; c < VoxelData.m_ChunkWidth; ++c) { m_World.m_Chunks[i, j].m_VoxelMap[k, d, c] = save.m_Chunks[index].m_VoxelMap[voxelIndex]; voxelIndex++; } } } m_World.m_Chunks[i, j].UpdateMeshData(); m_World.m_Chunks[i, j].m_Coord = save.m_Chunks[index].m_Coord; } index++; } } } } }