public void GenerateMap() { Texture2D texture2D; float[,] noiseMap; Noise noiseGen; var display = FindObjectOfType<MapDisplay>(); switch (mapDrawMode) { case MapDrawMode.HeightMap: noiseGen = new Noise(); noiseMap = noiseGen.GenerateFastNoiseMap(parameters, parameters.size, parameters.noisePosition); texture2D = TextureGenerator.TextureFromHeightMap(noiseMap); display.DrawMap(texture2D, parameters.size); break; case MapDrawMode.ColorMap: noiseGen = new Noise(); noiseMap = noiseGen.GenerateFastNoiseMap(parameters, parameters.size, parameters.noisePosition); texture2D = GenerateTexture(noiseMap); display.DrawMap(texture2D, parameters.size); break; case MapDrawMode.Mesh: if (!OverrideMesh) GenerateNewMap(); else { if (meshGameObject) DestroyImmediate(meshGameObject); meshGameObject = GenerateMapChunk(Vector3.zero); } break; case MapDrawMode.Terrain: var terrainData = TerrainGenerator.CreateTerrain(parameters, parameters.size); if (terrainData) if (!terrain) terrain = Terrain.CreateTerrainGameObject(terrainData); else terrain.GetComponent<Terrain>().terrainData = terrainData; break; case MapDrawMode.FullMap: GenerateFullMap(parameters, fullMapParameters); break; default: throw new ArgumentOutOfRangeException(); } }
public static TerrainData CreateTerrain(MapParameters par, int mapSize) { mapSize = Mathf.ClosestPowerOfTwo(mapSize); var noiseGen = new Noise(); var heightMap = noiseGen.GenerateFastNoiseMap(par, mapSize, par.noisePosition); var terrainData = new TerrainData { size = new Vector3(mapSize / 4, par.baseHeight, mapSize / 4), heightmapResolution = mapSize }; for (var x = 0; x < mapSize; x++) for (var y = 0; y < mapSize; y++) heightMap[x, y] = par.heightCurve.Evaluate(heightMap[x, y]); terrainData.SetHeights(0, 0, heightMap); return terrainData; }
public GameObject GenerateMapChunk(Vector3 position) { var noiseGen = new Noise(); var noiseMap = noiseGen.GenerateFastNoiseMap(parameters, parameters.size, parameters.noisePosition); return GenerateMapChunk(position, parameters, noiseMap); }