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(noiseMap[x, y] - falloffMap[x, y]); } if (useOverlay) { noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - overlayMap[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(TextureGenerator.TextureFromHeightMap(noiseMap)); } else if (drawMode == DrawMode.ColourMap) { display.DrawTexture(TextureGenerator.TextureFromColourMap(colourMap, mapWidth, mapHeight)); } else if (drawMode == DrawMode.FalloffMap) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(FalloffGenerator.GenerateFalloffMap(mapHeight))); } else if (drawMode == DrawMode.Mesh) { display.DrawMesh(MeshGenerator.GenerateTerrainMesh(noiseMap), TextureGenerator.TextureFromColourMap(colourMap, mapWidth, mapHeight)); } else if (drawMode == DrawMode.OverlayMap) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(OverlayGenerator.GenerateOverlayMap(mapHeight))); } }
void OnValidate() { if (lacunarity < 1) { lacunarity = 1; } if (octaves < 0) { octaves = 0; } falloffMap = FalloffGenerator.GenerateFalloffMap(mapHeight); overlayMap = OverlayGenerator.GenerateOverlayMap(mapHeight); }
void Awake() { falloffMap = FalloffGenerator.GenerateFalloffMap(mapHeight); overlayMap = OverlayGenerator.GenerateOverlayMap(mapHeight); }