public static void SaveChunk(Chunk chunk, bool temporary = false) { Assert.IsTrue(IsInitialized, "You need to initialize first!"); if (chunk == null) { return; } NativeList <int2> blocks = chunk.CompressBlocks(); Dictionary <int, string> palette = BlockProvider.GetBlockPalette(); string path = SaveFile(chunk.position, temporary); writing: try { using (BinaryWriter w = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate))) { WriteChunkInfo(w, chunk.position, palette, blocks); } } catch (DirectoryNotFoundException) { Directory.CreateDirectory(Path.GetDirectoryName(path)); goto writing; } blocks.Dispose(); }
public static VoxelJsonData GetJsonData(VoxelWorld world, bool ignoreEmptyChunks = false) { VoxelJsonData data = new VoxelJsonData(BlockProvider.GetBlockPalette()); List <Chunk> chunks = LoadAllChunks(world, ignoreEmptyChunks); VoxelJsonChunkData[] chunkData = new VoxelJsonChunkData[chunks.Count]; for (int i = 0; i < chunks.Count; i++) { chunkData[i] = new VoxelJsonChunkData(chunks[i]); } data.chunks = chunkData; for (int i = 0; i < chunks.Count; i++) { chunks[i].Dispose(true); } return(data); }