// Start is called before the first frame update void Start() { int mapWidth = 100; int mapHeight = 100; MapDisplay display = FindObjectOfType <MapDisplay>(); MapGen map = FindObjectOfType <MapGen>(); Vector2 offset = new Vector2(0, 0); int seed = Random.Range(-1000, 1000); float[,] noiseMap = Noise.GenerateNoiseMap(100, 100, map.noiseScale, 3, 0.2f, 3, seed, offset); Color[] colorMap = new Color[mapWidth * mapHeight]; for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { float currentHeight = noiseMap[x, y]; for (int i = 0; i < map.regions.Length; i++) { if (currentHeight < map.regions[i].height) { colorMap[(y * mapWidth) + x] = map.regions[i].color; break; } } } } display.DrawMesh(MeshGen.TerrainMeshGen(noiseMap, map.heightMultiplier, map.meshHeightCurve), ColorTexture.TextureColorMap(colorMap, mapWidth, mapHeight)); }
public void GenerateMap() { float[,] noiseMap = Noise.GenerateNoiseMap(mapWidth, mapHeight, noiseScale, octaves, persistence, lacunarity, seed, offset); Color[] colorMap = new Color[mapWidth * mapHeight]; for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { float currentHeight = noiseMap[x, y]; for (int i = 0; i < regions.Length; i++) { if (currentHeight < regions[i].height) { colorMap[(y * mapWidth) + x] = regions[i].color; break; } } } } MapDisplay display = FindObjectOfType <MapDisplay>(); if (drawMode == DrawMode.NoiseMap) { display.DrawTexture(ColorTexture.TextureHeightMap(noiseMap)); } else if (drawMode == DrawMode.ColorMap) { display.DrawTexture(ColorTexture.TextureColorMap(colorMap, mapWidth, mapHeight)); } else if (drawMode == DrawMode.Mesh) { display.DrawMesh(MeshGen.TerrainMeshGen(noiseMap, heightMultiplier, meshHeightCurve), ColorTexture.TextureColorMap(colorMap, mapWidth, mapHeight)); } }