Example #1
0
    public void GenerateMap()
    {
        float[,] noiseMap = Noise.GenerateNoiseMap(mapWidth, mapHeight, seed, noiseScale, octaves, persistance, lacunarity, offset);

        Color[] colourMap = new Color[mapWidth * mapHeight];

        for (int y = 0; y < mapHeight; y++)
        {
            for (int x = 0; x < mapWidth; x++)
            {
                if (useFallOff)
                {
                    noiseMap[x, y] = Mathf.Clamp01(fallOffMap[x, y] - noiseMap[x, y]);
                }

                float currentHeight = noiseMap[x, y];
                for (int i = 0; i < Regions.Length; i++)
                {
                    if (currentHeight <= Regions[i].height)
                    {
                        colourMap[y * mapWidth + x] = Regions[i].colour;
                        break;
                    }
                }
            }
        }

        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.drawTexture(TextureGen.textureFromHeightMap(noiseMap));
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            display.drawTexture(TextureGen.textureFromColourMap(colourMap, mapWidth, mapHeight));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.drawMesh(MeshGenerator.generateTerrainMesh(noiseMap, meshHeightMult, heightCurve, useFlatshading), TextureGen.textureFromColourMap(colourMap, mapWidth, mapHeight));
        }
        else if (drawMode == DrawMode.FallOff)
        {
            display.drawTexture(TextureGen.textureFromHeightMap(FalloffGen.GenerateFallOffMap(mapWidth)));
        }
    }
Example #2
0
    private void OnValidate()
    {
        if (mapWidth < 1)
        {
            mapWidth = 1;
        }
        if (mapHeight < 1)
        {
            mapHeight = 1;
        }
        if (lacunarity < 1)
        {
            lacunarity = 1;
        }
        if (octaves < 0)
        {
            octaves = 0;
        }

        fallOffMap = FalloffGen.GenerateFallOffMap(mapWidth);
    }
Example #3
0
 private void Awake()
 {
     fallOffMap = FalloffGen.GenerateFallOffMap(mapWidth);
     seed       = Random.Range(1, 10000000);
 }