public Save(Chunk chunk) { for (int x = 0; x < Chunk.chunkSize; x++) { for (int y = 0; y < Chunk.chunkSize; y++) { for (int z = 0; z < Chunk.chunkSize; z++) { if (!chunk.blocks[x, y, z].changed) { continue; } WorldPos pos = new WorldPos(x, y, z); blocks.Add(pos, chunk.blocks[x, y, z]); } } } }
public void CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x, y, z); GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject; Chunk newChunk = newChunkObject.GetComponent <Chunk>(); newChunk.pos = worldPos; newChunk.world = this; chunks.Add(worldPos, newChunk); //// Example Chunk Population //for (int xi = 0; xi < 16; xi++) //{ // for (int yi = 0; yi < 16; yi++) // { // for (int zi = 0; zi < 16; zi++) // { // if (yi <= 7) // { // SetBlock(x + xi, y + yi, z + zi, new BlockGrass()); // } // else // { // SetBlock(x + xi, y + yi, z + zi, new BlockAir()); // } // } // } //} //// End Example Chunk Population TerrainGen terrainGen = new TerrainGen(); newChunk = terrainGen.ChunkGen(newChunk); newChunk.SetBlocksUnmodified(); bool loaded = Serialization.Load(newChunk); }
public static string FileName(WorldPos chunkLocation) { string fileName = chunkLocation.x + "," + chunkLocation.y + "," + chunkLocation.z + ".bin"; return(fileName); }