public static void OnSavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game) { //Debug.Log("SaveOpen"); if (status == SavedGameRequestStatus.Success) { // handle reading or writing of saved game. if (saving) //Save the game { // Debug.Log("SaveGP"); SaveGooglePlay(game, ObjectSerializationExtension.SerializeToByteArray(loadedData), TimeSpan.FromMinutes(0)); } else //load the game { // Debug.Log("LoadGP"); LoadFromGooglePlay(game); } } else { // handle error //Debug.LogWarning("Could not open save game"); //Always save local, so ony loaded needs to be done here if (!saving) { LoadLocal(); } } }
private void SetupHelpLinks() { var helpMenuItem = new ToolStripMenuItem("Help"); mainMenuStrip.Items.Add(helpMenuItem); try { var helpLinksFile = ConfigurationManager.AppSettings["HelpLinksFile"]; var xmlSerializer = new ObjectSerializationExtension(_applicationLogger); var menuItems = xmlSerializer.DeSerializeObject <List <HelpLink> >(helpLinksFile); foreach (var menuItem in menuItems) { var toolStripMenuItem = new ToolStripMenuItem(menuItem.Text, null, OnHelpMenuItemClick); toolStripMenuItem.Tag = menuItem.Link; helpMenuItem.DropDownItems.Add(toolStripMenuItem); } } catch (Exception ex) { mainMenuStrip.Items.Remove(helpMenuItem); _applicationLogger.Log(ex.ToString(), LogLevel.Error); MessageBox.Show("Help links menu init failed"); } }
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++; } } } } }
void SaveGame() { WorldSave save = new WorldSave(); save.m_Seed = m_World.m_Seed; save.m_BlockTypes = m_World.m_BlockTypes; int index = 0; for (int i = 0; i < VoxelData.m_WorldSizeInChunks; ++i) { for (int j = 0; j < VoxelData.m_WorldSizeInChunks; ++j) { if (m_World.m_Chunks[i, j] != null) { save.m_Chunks[index] = new ChunkSave(); 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) { save.m_Chunks[index].m_VoxelMap[voxelIndex] = m_World.m_Chunks[i, j].m_VoxelMap[k, d, c]; voxelIndex++; } } } save.m_Chunks[index].m_Coord = m_World.m_Chunks[i, j].m_Coord; } index++; } } byte[] bytes = ObjectSerializationExtension.SerializeToByteArray(save); File.WriteAllBytes("data.dat", bytes); }