public void DrawMapInEditor() { HeightMapSettings.UpdateMeshHeights(TerrainMaterial, HeightMapSettings.MinHeight, HeightMapSettings.MaxHeight); HeightMapSettings.ApplyToMaterial(TerrainMaterial); HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(MeshSettings.NumVertsPerLine, HeightMapSettings, Vector2.zero); switch (drawMode) { case DrawMode.NoiseMap: DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap)); break; case DrawMode.Mesh: MeshData meshData = MeshGenerator.GenerateTerrainMesh(heightMap.Values, MeshSettings, editorPreviewLOD); Texture2D texture = TextureGenerator.TextureFromBiomeMap(BiomeMapGenerator.GenerateBiomeMap(heightMap.Values.GetLength(0) - 3, BiomeMapSettings, Vector2.zero)); DrawMesh(meshData, texture); break; case DrawMode.FalloffMap: DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(MeshSettings.NumVertsPerLine), 0, 1, HeightMapSettings))); break; case DrawMode.BiomeMap: DrawTexture(TextureGenerator.TextureFromBiomeMap(BiomeMapGenerator.GenerateBiomeMap(heightMap.Values.GetLength(0) - 3, BiomeMapSettings, Vector2.zero))); break; } }
/// <summary> /// Setup is called when the seed is set through the SetSeed RPC call /// </summary> private void Setup() { // Collect and fill the biomes Biome[] biomes = BiomeMapSettings.Biomes; BiomeResources = new Dictionary <int, BiomeResources>(); for (int i = 0; i < biomes.Length; i++) { int biomeIndex = (int)biomes[i].BiomeType; if (!BiomeResources.ContainsKey(biomeIndex)) { BiomeResources.Add(biomeIndex, new BiomeResources(biomes[i].Name, biomeIndex)); } } foreach (var worldResourceEntry in ResourceMapSettings.WorldResourceEntries) { List <int> selectedBiomes = worldResourceEntry.GetBiomes(); foreach (var selectedBiome in selectedBiomes) { if (BiomeResources.ContainsKey(selectedBiome)) { BiomeResources[selectedBiome].worldResourceEntries.Add(worldResourceEntry); } else { Debug.LogError("Given biomeId does not exist!"); } } } HeightMapSettings.UpdateMeshHeights(TerrainMeshMaterial, HeightMapSettings.MinHeight, HeightMapSettings.MaxHeight); HeightMapSettings.ApplyToMaterial(TerrainMeshMaterial); float maxViewDistance = detailLevels[detailLevels.Length - 1].VisibleDistanceThreshold; meshWorldSize = MeshSettings.MeshWorldSize; chunksVisibleInViewDistance = Mathf.RoundToInt(maxViewDistance / meshWorldSize); primaryViewer = new TerrainViewer(PlayerNetwork.LocalPlayer.transform, TerrainViewer.ViewerTypes.primary); UpdateVisibleChunks(); IsSetupFinished = true; OnSetupFinished?.Invoke(); }