private void OnGUI() { info.OnGUI(); if (GUILayout.Button("Sample HeightMap & NormalMap")) { PerlinNoiseMap map = new PerlinNoiseMap(info); Texture2D heightMap = null; Texture2D normalMap = null; map.Sample(out heightMap, out normalMap); byte[] bytes1 = heightMap.EncodeToPNG(); string heightMapPath = EditorUtility.SaveFilePanel("Save HeightMap", @"E:\UnityProject\Test1\Assets\Resources\", "HeightMap", "png"); if (!string.IsNullOrEmpty(heightMapPath)) { File.WriteAllBytes(heightMapPath, bytes1); Debug.Log("HeightMap: " + heightMapPath); } byte[] bytes2 = normalMap.EncodeToPNG(); string normalMapPath = EditorUtility.SaveFilePanel("Save NormalMap", @"E:\UnityProject\Test1\Assets\Resources\", "NormalMap", "png"); if (!string.IsNullOrEmpty(normalMapPath)) { File.WriteAllBytes(normalMapPath, bytes2); Debug.Log("NormalMap: " + normalMapPath); } } }
private void SetTileType() { // Sets the tiles type and sprite based off its x/y position // in the world int NumberOfTileTypes = Enum.GetNames(typeof(TileType)).Length; int tileTypeAsInt = PerlinNoiseMap.GetValueInRange((int)Pos.x, (int)Pos.y, WorldConfig.Seed, NumberOfTileTypes); Type = (TileType)tileTypeAsInt; SetSprite(); }
public float[,] getNoiseMap(int chunkX, int chunkY) { // initialize all of the different noise providers PerlinNoise = new PerlinNoiseMap(seed, mapSize, mapSize, scale, lacunarity, persistance, octaves); SimplexNoise = new SimplexNoiseMap(seed, mapSize, mapSize, scale, lacunarity, persistance, octaves); float[,] noiseMap = new float[0, 0]; switch (noiseType) { case "Perlin": { noiseMap = PerlinNoise.generateNoise(chunkX, chunkY); break; } case "Simplex": { noiseMap = SimplexNoise.generateNoise(chunkX, chunkY); break; } default: { // default to perlin noiseMap = PerlinNoise.generateNoise(chunkX, chunkY); break; } } // cache noise maps for later calls string chunkIndex = Utils.getChunkName(chunkX, chunkY); if (cachedNoiseMaps.ContainsKey(chunkIndex)) { cachedNoiseMaps.Remove(chunkIndex); } cachedNoiseMaps.Add(chunkIndex, noiseMap); return(noiseMap); }