public void DrawChunk() { /*Draw Chunk*/ for (int z = 0; z < World.chunkSize; z++) { for (int y = 0; y < World.chunkSize; y++) { for (int x = 0; x < World.chunkSize; x++) { _chunkData[x, y, z].Draw(); } } } //Old drawing Logic /*for (int z = 0; z < sizeZ; z++) * { * for (int y = 0; y < sizeY; y++) * { * for (int x = 0; x < sizeX; x++) * { * Vector3 pos = new Vector3(x,y,z); * Block _block = new Block(Block.BlockType.DIRT, pos, this.gameObject, _material); * _block.Draw(); * yield return null; * } * } * }*/ CombineQuads(); MeshCollider _blockCollider = _chunk.gameObject.AddComponent(typeof(MeshCollider)) as MeshCollider; _blockCollider.sharedMesh = _chunk.transform.GetComponent <MeshFilter>().mesh; status = chunckStatus.DONE; }
void BuildChunk() { bool dataFromFile = false; dataFromFile = Load(); _chunkData = new Block[World.chunkSize, World.chunkSize, World.chunkSize]; /*Create Chunk Data*/ for (int z = 0; z < World.chunkSize; z++) { for (int y = 0; y < World.chunkSize; y++) { for (int x = 0; x < World.chunkSize; x++) { Vector3 pos = new Vector3(x, y, z); Vector3 chunkPosition = _chunk.transform.position; int worldX = (int)(x + chunkPosition.x); int worldY = (int)(y + chunkPosition.y); int worldZ = (int)(z + chunkPosition.z); if (dataFromFile) { _chunkData[x, y, z] = new Block(_blockData.blockMatrix[x, y, z], pos, _chunk.gameObject, this); continue; } //Debug.Log(GenerationUtils.GenerateHeight(worldX, worldZ)); //if (GenerationUtils._BrownianMotion3D(worldX, worldY, worldZ, 3, 0.5f) < 0.40f) if (GenerationUtils.BrownianMotion3D(worldX, worldY, worldZ, 0.1f, 3) < 0.42f) { _chunkData[x, y, z] = new Block(Block.BlockType.AIR, pos, _chunk.gameObject, this); } else if (worldY <= GenerationUtils.GenerateStoneHeight(worldX, worldZ)) { if (GenerationUtils.BrownianMotion3D(worldX, worldY, worldZ, 0.1f, 2) < 0.4f && worldY <= 40) { _chunkData[x, y, z] = new Block(Block.BlockType.DIAMOND, pos, _chunk.gameObject, this); Debug.Log("Placing Diamonds"); } else if (GenerationUtils.BrownianMotion3D(worldX, worldY, worldZ, 0.3f, 3) < 0.41f && worldY <= 20) { _chunkData[x, y, z] = new Block(Block.BlockType.REDSTONE, pos, _chunk.gameObject, this); Debug.Log("Placing Red stone"); } else { _chunkData[x, y, z] = new Block(Block.BlockType.STONE, pos, _chunk.gameObject, this); } } else if (worldY == GenerationUtils.GenerateHeight(worldX, worldZ)) { _chunkData[x, y, z] = new Block(Block.BlockType.GRASS, pos, _chunk.gameObject, this); } else if (worldY <= GenerationUtils.GenerateHeight(worldX, worldZ)) { _chunkData[x, y, z] = new Block(Block.BlockType.DIRT, pos, _chunk.gameObject, this); } else { _chunkData[x, y, z] = new Block(Block.BlockType.AIR, pos, _chunk.gameObject, this); } status = chunckStatus.DRAW; } } } }