Exemple #1
0
    /* Vector2 playerPosition */
    public void Render(bool useTerrainColors)
    {
        if (terrainChunks[0, 0] != null)
        {
            this.Clear();
        }

        for (int x = 0; x < chunksPerDimension; x++)
        {
            int relativeX = x - (chunksPerDimension - 1) / 2;

            for (int y = 0; y < chunksPerDimension; y++)
            {
                int relativeY = y - (chunksPerDimension - 1) / 2;

                /* Set Noise generation offset to chunkSize * global chunk dimension index */
                float[,] currentNoiseArray = noiseGenerator.GenerateNoiseArr(relativeX, relativeY);

                Mesh      mesh = GenerateMeshFromNoiseMap(currentNoiseArray, maxTerrainHeight, terrainTypes[0].heightCutoff);
                Texture2D texture;

                if (useTerrainColors)
                {
                    texture = Generate2DTextureForTerrains(currentNoiseArray, terrainTypes);
                }
                else
                {
                    texture = Texture2DFromNoiseMap(currentNoiseArray);
                }

                terrainChunks[x, y] = new TerrainChunk(new Vector2(relativeX, relativeY),
                                                       new Vector2(currentNoiseArray.GetLength(0), currentNoiseArray.GetLength(1)),
                                                       terrainObject.transform, mesh, texture);
            }
        }
    }