public void SaveData() { Chunk chunk = GetComponent <Chunk>(); string compressedData = ChunkDataFiles.CompressData(chunk); WriteChunkData(chunk.ChunkIndex, compressedData); }
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); } }
//将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)"); }
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: 保存当前世界成功。"); }
public static void SaveWorldInstant() { ChunkDataFiles.SaveAllChunksInstant(); }
public static void SaveWorld() { Engine.EngineInstance.StartCoroutine(ChunkDataFiles.SaveAllChunks()); }