Пример #1
0
    public void GenerateMap()
    { // (拿取)fetching the 2D noisemap from noise class
        float[,] noiseMap = Noise.GenerateNoiseMap(mapChunkSize, mapChunkSize, seed, noiseData.noiseScale, noiseData.octaves, noiseData.persistance, noiseData.lancunarity, noiseData.offset);

        Color[] colourMap = new Color[mapChunkSize * mapChunkSize];

        for (int y = 0; y < mapChunkSize; y++)
        {
            for (int x = 0; x < mapChunkSize; x++)
            {
                float currentHeight = noiseMap[x, y]; // height at this point = noisemap x by y
                for (int i = 0; i < regions.Length; i++)
                {                                     // loop the paramter of  the all array of TerrainTypes[] regions
                    if (currentHeight <= regions[i].height)
                    {
                        colourMap[y * mapChunkSize + x] = regions[i].colour; // save the color of each pixel of noise map
                        break;
                    }
                }
            }
        }

        textureData.UpdateMeshHeights(terrainMaterial, minHeight, maxHeight);

        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.Noisemap)
        {
            display.DrawTexture(TextureGenerator.GenerateNoiseMap(noiseMap));
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            display.DrawTexture(TextureGenerator.GenerateColourMap(colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(noiseMap, terrainData.meshHeightMultiplier, terrainData.meshHeightCurve, levelOfDetail), TextureGenerator.GenerateColourMap(colourMap, mapChunkSize, mapChunkSize));
        }
    }