Пример #1
0
 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();
         }
     }
 }
Пример #2
0
    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);
    }