Example #1
0
        public TerrainChunk Initialize(TerrainManager terrainManager, int cellsPerChunk, ChunkLocation location, TerrainGenerator terrainGenerator, Material chunkMaterial)
        {
            this.terrainManager = terrainManager;

            transform.position = new Vector3(location.GetX() * cellsPerChunk, 0, location.GetZ() * cellsPerChunk);
            transform.name     = "Chunk";
            gameObject.layer   = 8;

            this.location      = location;
            this.cellsPerChunk = cellsPerChunk;

            cellHeights = new float[cellsPerChunk + 1, cellsPerChunk + 1];
            for (int i = 0; i < cellsPerChunk + 1; i++)
            {
                for (int j = 0; j < cellsPerChunk + 1; j++)
                {
                    cellHeights[i, j] = terrainGenerator.GetTerrainHeight(i + location.GetAbsX(), j + location.GetAbsZ());
                }
            }

            chunkCells = new TerrainCell[cellsPerChunk, cellsPerChunk];
            for (int i = 0; i < cellsPerChunk; i++)
            {
                for (int j = 0; j < cellsPerChunk; j++)
                {
                    CellLocation loc = new CellLocation(i, j, location);

                    chunkCells[i, j] = new TerrainCell(loc, terrainGenerator);
                }
            }

            m_material = chunkMaterial;
            GetComponent <MeshRenderer>().material = m_material;

            return(this);
        }
Example #2
0
 public int GetAbsX()
 {
     return(x + parent.GetAbsX());
 }