Exemplo n.º 1
0
    public void GenMap()
    {
        _seed = (int)Random.Range(0f, 100000.0f);
        var nmap = Perlin.GenNmap(_mapWidth, _mapHeight, _noiseScale, _octaves, _lacunarity, _persistance, _seed);
        var cmap = new Color[_mapWidth * _mapHeight];

        for (var x = 0; x < _mapHeight; x++)
        {
            for (var y = 0; y < _mapWidth; y++)
            {
                var currentHeight = nmap[x, y];
                for (var i = 0; i < _biomeTypes.Length; i++)
                {
                    if (!(currentHeight <= _biomeTypes[i].Height))
                    {
                        continue;
                    }
                    cmap[y * _mapWidth + x] = _biomeTypes[i].Color;
                    break;
                }
            }
        }

        _mapRenderer = GetComponent <MapRenderer>();
        _mapRenderer.DrawMesh(MeshGen.Generate(nmap, _meshHeightMultiplier, _meshHeightCurve), _mapRenderer.ColorTexture(cmap, _mapWidth, _mapHeight));
    }