public static void SaveChunk(Chunk _chunk) { ChunkSave chunk_save = new ChunkSave(_chunk); //create save data from chunk if (chunk_save.voxels.Count == 0) //if no edited voxels { return; //don't bother saving } string save_file = GetSaveLocation(_chunk.voxel_world.save_name); save_file += GetChunkFileName(_chunk.voxel_world_position);//add save name onto file directory IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream(save_file, FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, chunk_save);//serialise the save object stream.Close(); }
public static void SaveChunk(Chunk chunk) { ChunkSave save = new ChunkSave(chunk); if (save.blocks.Count == 0) { return; } string saveFile = SaveLocation(chunk.world.worldName); saveFile += ChunkFileName(chunk.pos); IFormatter form = new BinaryFormatter(); Stream stream = new FileStream(saveFile, FileMode.Create, FileAccess.Write, FileShare.None); form.Serialize(stream, save); stream.Close(); }
public static bool Load(Chunk _chunk) { string save_file = GetSaveLocation(_chunk.voxel_world.save_name); save_file += GetChunkFileName(_chunk.voxel_world_position); //determine possible directory of chunk save if (!File.Exists(save_file)) //if no save don't attempt to load { return(false); } IFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(save_file, FileMode.Open); //open file ChunkSave chunk_save = (ChunkSave)formatter.Deserialize(stream); //unserialise file into chunk save foreach (KeyValuePair <int, Voxel> voxel in chunk_save.voxels) { _chunk.voxels[voxel.Key] = voxel.Value; } stream.Close();//close file stream return(true); }
public static bool LoadChunk(Chunk chunk) { string saveFile = SaveLocation(chunk.world.worldName); saveFile += ChunkFileName(chunk.pos); if (!File.Exists(saveFile)) { return(false); } IFormatter form = new BinaryFormatter(); FileStream stream = new FileStream(saveFile, FileMode.Open); ChunkSave save = (ChunkSave)form.Deserialize(stream); foreach (var block in save.blocks) { chunk.blocks[block.Key.x, block.Key.y, block.Key.z] = block.Value; } stream.Close(); return(true); }
// Methods public Chunk StartGenerate(int x, int y, System.Random rand, Directions direction, GameObject map, bool isPrisme = false) { // Load the chunk this.x = x; this.y = y; this.rand = rand; this.cs = map.GetComponent<Save>().LoadChunk(x, y); this.isPrisme = isPrisme; this.b = BiomeDatabase.RandBiome(this.rand); Spawn(new Vector3(x * Size, 0, y * Size), Quaternion.Euler(new Vector3(0, 90 * (int)direction, 0)), map.transform); // Set good biome this.posIslands = new List<Vector3>(); foreach (Transform child in Prefab.transform) if (child.name.Contains("Island")) { this.posIslands.Add(child.transform.position); if (child.GetComponent<MeshRenderer>().materials[0].name.Contains("Rock")) child.GetComponent<MeshRenderer>().materials = new Material[2] { b.Rock, b.Grass }; else child.GetComponent<MeshRenderer>().materials = new Material[2] { b.Grass, b.Rock }; } Prefab.GetComponent<SyncChunk>().BiomeId = b.ID; Prefab.GetComponent<SyncChunk>().IsCristal = isPrisme; this.ancres = new List<Transform>(); foreach (Transform content in Prefab.transform) if (content.CompareTag("Elements")) foreach (Transform ancre in content.transform) ancres.Add(ancre); return this; }