public void CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x, y, z); GameObject newChunkObject = Instantiate(ChunkPrefab, Vector3.zero, Quaternion.Euler(Vector3.zero)) as GameObject; newChunkObject.transform.parent = gameObject.transform; newChunkObject.transform.localPosition = new Vector3(x, y, z); Chunk newChunk = newChunkObject.GetComponent<Chunk>(); newChunk.Pos = worldPos; newChunk.Planet = this; Chunks.Add(worldPos, newChunk); for (int xi = 0; xi < 16; xi++) { for (int yi = 0; yi < 16; yi++) { for (int zi = 0; zi < 16; zi++) { double heightModifier = PerlinGenerator.GetValue(new Vector3(xi + 0.01f, yi + 0.01f, zi + 0.01f)); Debug.Log(string.Format("Accepted x:{0}, y:{1}, z:{2} and got {3}", xi + 0.01f, yi, zi, heightModifier)); Debug.Log(heightModifier); if (heightModifier == 0) { throw new Exception (); } if (Vector3.Distance(new Vector3(x + xi, y + yi, z + zi), Vector3.zero) < Radius - (heightModifier * Scale)) { SetBlock(x + xi, y + yi, z + zi, new Block()); } else { SetBlock(x + xi, y + yi, z + zi, new BlockAir()); } } } } Debug.Log(string.Format("Finished chunk generation for x:{0}, y:{1}, z:{2}", worldPos.x, worldPos.y, worldPos.z)); }
public void CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x, y, z); GameObject newChunkObject = Instantiate(ChunkPrefab, Vector3.zero, Quaternion.Euler(Vector3.zero)) as GameObject; newChunkObject.transform.parent = gameObject.transform; newChunkObject.transform.localPosition = new Vector3(x, y, z); Chunk newChunk = newChunkObject.GetComponent <Chunk>(); newChunk.Pos = worldPos; newChunk.Planet = this; Chunks.Add(worldPos, newChunk); for (int xi = 0; xi < 16; xi++) { for (int yi = 0; yi < 16; yi++) { for (int zi = 0; zi < 16; zi++) { double heightModifier = PerlinGenerator.GetValue(new Vector3(xi + 0.01f, yi + 0.01f, zi + 0.01f)); Debug.Log(string.Format("Accepted x:{0}, y:{1}, z:{2} and got {3}", xi + 0.01f, yi, zi, heightModifier)); Debug.Log(heightModifier); if (heightModifier == 0) { throw new Exception(); } if (Vector3.Distance(new Vector3(x + xi, y + yi, z + zi), Vector3.zero) < Radius - (heightModifier * Scale)) { SetBlock(x + xi, y + yi, z + zi, new Block()); } else { SetBlock(x + xi, y + yi, z + zi, new BlockAir()); } } } } Debug.Log(string.Format("Finished chunk generation for x:{0}, y:{1}, z:{2}", worldPos.x, worldPos.y, worldPos.z)); }
public Chunk GetChunk(int x, int y, int z) { WorldPos pos = new WorldPos(); float multiplier = Chunk.CHUNK_SIZE; pos.x = Mathf.FloorToInt(x / multiplier) * Chunk.CHUNK_SIZE; pos.y = Mathf.FloorToInt(y / multiplier) * Chunk.CHUNK_SIZE; pos.z = Mathf.FloorToInt(z / multiplier) * Chunk.CHUNK_SIZE; Chunk containerChunk = null; Chunks.TryGetValue(pos, out containerChunk); return containerChunk; }