Пример #1
0
        public void SaveData()
        {
            Chunk  chunk          = GetComponent <Chunk>();
            string compressedData = ChunkDataFiles.CompressData(chunk);

            WriteChunkData(chunk.ChunkIndex, compressedData);
        }
Пример #2
0
        public static Dictionary <string, string[]> LoadedRegions;      // 载入的chunk数据

        //从文件中载入数据,未找到文件的话就返回false
        public bool LoadData()
        {
            Chunk  chunk     = GetComponent <Chunk>();
            string chunkData = GetChunkData(chunk.ChunkIndex);

            if (chunkData != "")
            {
                ChunkDataFiles.DecompressData(chunk, GetChunkData(chunk.ChunkIndex));
                chunk.VoxelsDone = true;
                return(true);
            }

            else
            {
                return(false);
            }
        }
Пример #3
0
        //将data从temp写入文件
        public static void SaveAllChunksInstant()
        {
            if (!Engine.SaveVoxelData)
            {
                Debug.LogWarning("CubeMaster: 不允许保存。请在Engine中设置。");
                return;
            }

            // 对每一个chunk,把数据写入内存
            foreach (Chunk chunk in ChunkManager.Chunks.Values)
            {
                chunk.gameObject.GetComponent <ChunkDataFiles>().SaveData();
            }

            // 写入本地
            ChunkDataFiles.WriteLoadedChunks();

            Debug.Log("CubeMaster: World saved successfully. (Instant)");
        }
Пример #4
0
        public static IEnumerator SaveAllChunks()
        {
            if (!Engine.SaveVoxelData)
            {
                Debug.LogWarning("CubeMaster: 不允许保存。请在Engine中设置。");
                yield break;
            }

            while (ChunkDataFiles.SavingChunks)
            {
                yield return(new WaitForEndOfFrame());
            }
            ChunkDataFiles.SavingChunks = true;

            //对于每一个chunk,把数据保存到内存中
            int          count        = 0;
            List <Chunk> chunksToSave = new List <Chunk>(ChunkManager.Chunks.Values);


            foreach (Chunk chunk in chunksToSave)
            {
                chunk.gameObject.GetComponent <ChunkDataFiles>().SaveData();
                count++;
                if (count > Engine.MaxChunkSaves)
                {
                    yield return(new WaitForEndOfFrame());

                    count = 0;
                }
            }

            // 把数据写入到本地
            ChunkDataFiles.WriteLoadedChunks();
            ChunkDataFiles.SavingChunks = false;

            Debug.Log("CubeMaster: 保存当前世界成功。");
        }
Пример #5
0
 public static void SaveWorldInstant()
 {
     ChunkDataFiles.SaveAllChunksInstant();
 }
Пример #6
0
 public static void SaveWorld()
 {
     Engine.EngineInstance.StartCoroutine(ChunkDataFiles.SaveAllChunks());
 }