public override void OnInspectorGUI() { int viewWidth = (int)(EditorGUIUtility.currentViewWidth - 100); serializedObject.Update(); CustomTerrain terrain = (CustomTerrain)target; // scrollbar starting code Rect r = EditorGUILayout.BeginVertical(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(r.width), GUILayout.Height(r.height)); EditorGUI.indentLevel++; EditorGUILayout.PropertyField(resetTerrain); showRandom = EditorGUILayout.Foldout(showRandom, "Random"); if (showRandom) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Set Heights Between Random Values", EditorStyles.boldLabel); EditorGUILayout.PropertyField(randomHeightRange); if (GUILayout.Button("Random Heights")) { terrain.RandomTerrain(); } } showLoadHeights = EditorGUILayout.Foldout(showLoadHeights, "Load Heights"); if (showLoadHeights) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Load Heights From Texture", EditorStyles.boldLabel); EditorGUILayout.PropertyField(heightMapImage); EditorGUILayout.PropertyField(heightMapScale); if (GUILayout.Button("Load Texture")) { terrain.LoadTexture(); } } showPerlin = EditorGUILayout.Foldout(showPerlin, "Single Perlin Noise"); if (showPerlin) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Set Heights with Perlin Noise", EditorStyles.boldLabel); EditorGUILayout.Slider(perlinXScale, 0, 1, new GUIContent("X Scale")); EditorGUILayout.Slider(perlinYScale, 0, 1, new GUIContent("Y Scale")); EditorGUILayout.IntSlider(perlinOffsetX, 0, 10000, new GUIContent("X Offset")); EditorGUILayout.IntSlider(perlinOffsetY, 0, 10000, new GUIContent("Y Offset")); EditorGUILayout.IntSlider(perlinOctaves, 1, 10, new GUIContent("Octaves")); EditorGUILayout.Slider(perlinPersistence, 0.1f, 10, new GUIContent("Persistence")); EditorGUILayout.Slider(perlinFrequencyMultiplier, 2, 10, new GUIContent("Frequency Multiplier")); EditorGUILayout.Slider(perlinHeightScale, 0, 1, new GUIContent("Height Scale")); if (GUILayout.Button("Perlin Noise")) { terrain.Perlin(); } } showMultiplePerlin = EditorGUILayout.Foldout(showMultiplePerlin, "Multiple Perlin Noise"); if (showMultiplePerlin) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Multiple Perlin Noise", EditorStyles.boldLabel); perlinParameterTable = GUITableLayout.DrawTable(perlinParameterTable, perlinParameters); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewPerlin(); } if (GUILayout.Button("-")) { terrain.RemovePerlin(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Multiple Perlin")) { terrain.MultiplePerlin(); } } showVoronoi = EditorGUILayout.Foldout(showVoronoi, "Voronoi"); if (showVoronoi) { EditorGUILayout.IntSlider(voronoiPeakCount, 1, 10, new GUIContent("Peak Count")); EditorGUILayout.Slider(voronoiFalloff, 0, 10, new GUIContent("Falloff")); EditorGUILayout.Slider(voronoiDropoff, 0, 10, new GUIContent("Dropoff")); EditorGUILayout.Slider(voronoiMinHeight, 0, 1, new GUIContent("Min Height")); EditorGUILayout.Slider(voronoiMaxHeight, 0, 1, new GUIContent("Max Height")); EditorGUILayout.PropertyField(voronoiType); if (GUILayout.Button("Voronoi")) { terrain.Voronoi(); } } showMidPointDisplacement = EditorGUILayout.Foldout(showMidPointDisplacement, "Mid Point Displacement"); if (showMidPointDisplacement) { EditorGUILayout.Slider(mpdMinHeight, -10, 0, new GUIContent("Min Height")); EditorGUILayout.Slider(mpdMaxHeight, 0, 10, new GUIContent("Max Height")); EditorGUILayout.Slider(mpdRoughness, 0, 5, new GUIContent("Roughness")); EditorGUILayout.Slider(mpdHeightDampenerPower, 0, 1, new GUIContent("Height Dampener Power")); if (GUILayout.Button("MPD")) { terrain.MidPointDisplacement(); } } showSplatMaps = EditorGUILayout.Foldout(showSplatMaps, "Splat Maps"); if (showSplatMaps) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Splat Maps", EditorStyles.boldLabel); splatMapTable = GUITableLayout.DrawTable(splatMapTable, splatHeights); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewSplatHeight(); } if (GUILayout.Button("-")) { terrain.RemoveSplatHeight(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply SplatMaps")) { terrain.ApplySplatMaps(); } } showVegetation = EditorGUILayout.Foldout(showVegetation, "Vegetation"); if (showVegetation) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Vegetation", EditorStyles.boldLabel); EditorGUILayout.IntSlider(maxTrees, 0, 10000, new GUIContent("Maximum Trees")); EditorGUILayout.IntSlider(treeSpacing, 2, 20, new GUIContent("Tree Spacing")); vegetationTable = GUITableLayout.DrawTable(vegetationTable, vegetation); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewVegetation(); } if (GUILayout.Button("-")) { terrain.RemoveVegetation(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Vegetation")) { terrain.ApplyVegetation(); } } showDetails = EditorGUILayout.Foldout(showDetails, "Details"); if (showDetails) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Details", EditorStyles.boldLabel); EditorGUILayout.IntSlider(maxDetails, 0, 10000, new GUIContent("Maximum Details")); EditorGUILayout.IntSlider(detailSpacing, 1, 20, new GUIContent("Detail Spacing")); detailsTable = GUITableLayout.DrawTable(detailsTable, details); // sync unity's detail distance with max details value from slider // so we can see all the details while developing. may want to dial back if framerate // is affected terrain.GetComponent <Terrain>().detailObjectDistance = maxDetails.intValue; GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewDetails(); } if (GUILayout.Button("-")) { terrain.RemoveDetails(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Details")) { terrain.ApplyDetails(); } } showWater = EditorGUILayout.Foldout(showWater, "Water"); if (showWater) { EditorGUILayout.Slider(waterHeight, 0, 1, new GUIContent("Water Height")); EditorGUILayout.PropertyField(waterGameObject); if (GUILayout.Button("Apply Water")) { terrain.ApplyWater(); } EditorGUILayout.PropertyField(shorelineMaterial); if (GUILayout.Button("Draw Shoreline")) { terrain.DrawShoreline(); } } showErosion = EditorGUILayout.Foldout(showErosion, "Erosion"); if (showErosion) { EditorGUILayout.PropertyField(erosionType); EditorGUILayout.Slider(erosionStrength, 0, 1, new GUIContent("Erosion Strength")); EditorGUILayout.Slider(erosionAmount, 0, 1, new GUIContent("Erosion Amount")); EditorGUILayout.IntSlider(droplets, 0, 500, new GUIContent("Droplets")); EditorGUILayout.Slider(solubility, 0.001f, 1, new GUIContent("Solubility")); EditorGUILayout.IntSlider(springsPerDroplet, 0, 20, new GUIContent("Springs per River")); EditorGUILayout.IntSlider(erosionSmoothAmount, 0, 10, new GUIContent("Smooth Amount")); if (GUILayout.Button("Erode")) { terrain.Erode(); } } showClouds = EditorGUILayout.Foldout(showClouds, "Clouds"); if (showClouds) { EditorGUILayout.PropertyField(numberOfClouds, new GUIContent("Number of Clouds")); EditorGUILayout.PropertyField(particlesPerCloud, new GUIContent("Particles per Cloud")); EditorGUILayout.PropertyField(cloudParticleSize, new GUIContent("Cloud Particle Size")); EditorGUILayout.PropertyField(cloudMinSize, new GUIContent("Min Size")); EditorGUILayout.PropertyField(cloudMaxSize, new GUIContent("Max Size")); EditorGUILayout.PropertyField(cloudMaterial, new GUIContent("Cloud Material")); EditorGUILayout.PropertyField(cloudShadowMaterial, new GUIContent("Cloud Shadow Material")); EditorGUILayout.PropertyField(cloudColor, new GUIContent("Color")); EditorGUILayout.PropertyField(cloudLiningColor, new GUIContent("Lining")); EditorGUILayout.PropertyField(cloudMinSpeed, new GUIContent("Min Speed")); EditorGUILayout.PropertyField(cloudMaxSpeed, new GUIContent("Max Speed")); EditorGUILayout.PropertyField(cloudDistanceTraveled, new GUIContent("Distance Traveled")); if (GUILayout.Button("Generate Clouds")) { terrain.GenerateClouds(); } } showSmooth = EditorGUILayout.Foldout(showSmooth, "Smooth Terrain"); if (showSmooth) { EditorGUILayout.IntSlider(smoothAmount, 1, 10, new GUIContent("Smooth Amount")); if (GUILayout.Button("Smooth")) { terrain.SmoothStandalone(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); if (GUILayout.Button("Reset Terrain")) { terrain.ResetTerrain(); } showHeightMap = EditorGUILayout.Foldout(showHeightMap, "Height Map"); if (showHeightMap) { // begin centered row GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label(heightMapTexture, GUILayout.Width(viewWidth), GUILayout.Height(viewWidth)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); // end centered row // begin centered row GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Refresh", GUILayout.Width(viewWidth))) { float[,] heights = terrain.terrainData.GetHeights(0, 0, terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight); LoadArrayToTexture2D(heightMapTexture, heights); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); // end centered row } // scrollbar ending code EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { serializedObject.Update(); CustomTerrain terrain = (CustomTerrain)target; EditorGUILayout.PropertyField(resetTerrain); showRandom = EditorGUILayout.Foldout(showRandom, "Random"); if (showRandom) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Set Heights Between Random Values", EditorStyles.boldLabel); EditorGUILayout.PropertyField(randomHeightRange); if (GUILayout.Button("Random Heights")) { terrain.RandomTerrain(); } } showLoadHeights = EditorGUILayout.Foldout(showLoadHeights, "Load Heights"); if (showLoadHeights) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Load Heights From Texture", EditorStyles.boldLabel); EditorGUILayout.PropertyField(heightMapImage); EditorGUILayout.PropertyField(heightMapScale); if (GUILayout.Button("Load Texture")) { terrain.LoadTexture(); } } showPerlin = EditorGUILayout.Foldout(showPerlin, "Single Perlin Noise"); if (showPerlin) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Perlin Noise Heights", EditorStyles.boldLabel); EditorGUILayout.Slider(perlinXScale, 0f, 0.1f, new GUIContent("X Scale")); EditorGUILayout.Slider(perlinYScale, 0f, 0.1f, new GUIContent("Y Scale")); EditorGUILayout.IntSlider(perlinOffsetX, 0, 10000, new GUIContent("X Offset")); EditorGUILayout.IntSlider(perlinOffsetY, 0, 10000, new GUIContent("Y Offset")); // Fractal Brownian Motion additions EditorGUILayout.IntSlider(perlinOctaves, 1, 10, new GUIContent("Octaves")); EditorGUILayout.Slider(perlinPersistance, 0.1f, 10, new GUIContent("Persistance")); EditorGUILayout.Slider(perlinHeightScale, 0, 1, new GUIContent("Height Scale")); if (GUILayout.Button("Perlin Noise")) { terrain.Perlin(); } } showMultiplePerlin = EditorGUILayout.Foldout(showMultiplePerlin, "Multiple Perlin Noise"); if (showMultiplePerlin) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Multiple Perlin Noise", EditorStyles.boldLabel); perlinParameterTable = GUITableLayout.DrawTable(perlinParameterTable, perlinParameters); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewPerlin(); } if (GUILayout.Button("-")) { terrain.RemovePerlin(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Multiple Perlin")) { terrain.MultiplePerlinTerrain(); } } showVoronoi = EditorGUILayout.Foldout(showVoronoi, "Voronoi"); if (showVoronoi) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.IntSlider(peakCount, 1, 10, new GUIContent("Peak Count")); EditorGUILayout.Slider(fallOff, 0f, 10f, new GUIContent("Falloff")); EditorGUILayout.Slider(dropOff, 0f, 10f, new GUIContent("Dropoff")); EditorGUILayout.Slider(minHeight, 0f, 1f, new GUIContent("Min Height")); EditorGUILayout.Slider(maxHeight, 0f, 1f, new GUIContent("Max Height")); EditorGUILayout.PropertyField(voronoiType); if (GUILayout.Button("Voronoi")) { terrain.Voronoi(); } } showMPD = EditorGUILayout.Foldout(showMPD, "Midpoint Displacement"); if (showMPD) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.PropertyField(mdpMinHeight, new GUIContent("Min Height")); EditorGUILayout.PropertyField(mdpMaxHeight, new GUIContent("Max Height")); EditorGUILayout.PropertyField(roughness, new GUIContent("Roughness")); EditorGUILayout.PropertyField(heightDampenerPower, new GUIContent("Height Damp. Pow")); if (GUILayout.Button("MPD")) { terrain.MidpointDisplacement(); } } showSplatMaps = EditorGUILayout.Foldout(showSplatMaps, "Splat Maps"); if (showSplatMaps) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Splat Maps", EditorStyles.boldLabel); splatMapTable = GUITableLayout.DrawTable(splatMapTable, serializedObject.FindProperty("splatHeights")); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewSplatHeight(); } if (GUILayout.Button("-")) { terrain.RemoveSplatHeight(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply SplatMaps")) { terrain.SplatMaps(); } } showVegetation = EditorGUILayout.Foldout(showVegetation, "Vegetation"); if (showVegetation) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.IntSlider(maxTrees, 100, 10000, new GUIContent("Max Trees")); EditorGUILayout.IntSlider(treeSpacing, 1, 100, new GUIContent("Tree Spacing")); GUILayout.Label("Vegetation", EditorStyles.boldLabel); vegetationTable = GUITableLayout.DrawTable(vegetationTable, serializedObject.FindProperty("vegetation")); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewVegetation(); } if (GUILayout.Button("-")) { terrain.RemoveVegetation(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Vegetation")) { terrain.PlantVegetation(); } } showDetail = EditorGUILayout.Foldout(showDetail, "Detail"); if (showDetail) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.IntSlider(maxDetails, 100, 10000, new GUIContent("Max Distance")); EditorGUILayout.IntSlider(detailSpacing, 1, 100, new GUIContent("Detail Spacing")); GUILayout.Label("Details", EditorStyles.boldLabel); detailsTable = GUITableLayout.DrawTable(detailsTable, serializedObject.FindProperty("details")); terrain.GetComponent <Terrain>().detailObjectDistance = maxDetails.intValue; GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewDetail(); } if (GUILayout.Button("-")) { terrain.RemoveDetails(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Details")) { terrain.PlaceDetails(); } } showWater = EditorGUILayout.Foldout(showWater, "Water"); if (showWater) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Water", EditorStyles.boldLabel); EditorGUILayout.Slider(waterHeight, 0f, 1.0f, new GUIContent("Water Height")); EditorGUILayout.PropertyField(waterGO, new GUIContent("Water GO")); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Add Water")) { terrain.AddWater(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(shoreLineMaterial, new GUIContent("Shore Line Material")); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Add Shoreline")) { terrain.DrawShoreline(); } EditorGUILayout.EndHorizontal(); } showErosion = EditorGUILayout.Foldout(showErosion, "Erosion"); if (showErosion) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.PropertyField(erosionType); EditorGUILayout.Slider(erosionStrength, 0f, 1.0f, new GUIContent("Erosion Strength")); EditorGUILayout.Slider(erosionAmount, 0f, 0.5f, new GUIContent("Erosion Amount")); EditorGUILayout.IntSlider(droplets, 1, 500, new GUIContent("Droplets")); EditorGUILayout.Slider(solubility, 0.001f, 1.0f, new GUIContent("Solubility")); EditorGUILayout.IntSlider(springsPerRiver, 0, 20, new GUIContent("Springs Per River")); EditorGUILayout.IntSlider(erosionSmoothAmount, 0, 10, new GUIContent("Smooth Amount")); if (GUILayout.Button("Erode")) { terrain.Erode(); } } showClouds = EditorGUILayout.Foldout(showClouds, "Clouds"); if (showClouds) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.PropertyField(numClouds, new GUIContent("Number of Clouds")); EditorGUILayout.PropertyField(particlesPerCloud, new GUIContent("Particles Per Cloud")); EditorGUILayout.PropertyField(cloudStartSize, new GUIContent("Cloud Start Size")); EditorGUILayout.PropertyField(cloudScaleMin, new GUIContent("Scale Min")); EditorGUILayout.PropertyField(cloudScaleMax, new GUIContent("Scale Max")); EditorGUILayout.PropertyField(cloudMaterial, new GUIContent("Cloud Material")); EditorGUILayout.PropertyField(cloudShadowMaterial, new GUIContent("Cloud Shadow Material")); EditorGUILayout.PropertyField(cloudColour, new GUIContent("Colour")); EditorGUILayout.PropertyField(cloudLining, new GUIContent("Lining")); EditorGUILayout.PropertyField(cloudMinSpeed, new GUIContent("Min Speed")); EditorGUILayout.PropertyField(cloudMaxSpeed, new GUIContent("Max Speed")); EditorGUILayout.PropertyField(cloudRange, new GUIContent("Distance Travelled")); if (GUILayout.Button("Generate Clouds")) { terrain.GenerateClouds(); } } showSmooth = EditorGUILayout.Foldout(showSmooth, "Smooth Terrain"); if (showSmooth) { EditorGUILayout.IntSlider(peakCount, 1, 10, new GUIContent("Smooth Aamount")); if (GUILayout.Button("Smooth")) { terrain.Smooth(); } } showHeightMap = EditorGUILayout.Foldout(showHeightMap, "Height Map"); if (showHeightMap) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); int hmtSize = (int)(EditorGUIUtility.currentViewWidth - 100); GUILayout.Label(hmTexture, GUILayout.Width(hmtSize), GUILayout.Height(hmtSize)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Refresh", GUILayout.Width(hmtSize))) { float[,] heightMap = terrain.terrainData.GetHeights(0, 0, terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight); for (int y = 0; y < terrain.terrainData.heightmapHeight; y++) { for (int x = 0; x < terrain.terrainData.heightmapWidth; x++) { hmTexture.SetPixel(x, y, new Color(heightMap[x, y], heightMap[x, y], heightMap[x, y], 1)); } } hmTexture.Apply(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); if (GUILayout.Button("Reset Terrain")) { terrain.ResetTerrain(); } serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { serializedObject.Update(); CustomTerrain terrain = (CustomTerrain)target; //ScrollBar Starting code Rect r = EditorGUILayout.BeginVertical(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(r.width), GUILayout.Height(r.height)); EditorGUI.indentLevel++; EditorGUILayout.PropertyField(resetTerrain); showRandom = EditorGUILayout.Foldout(showRandom, "Random"); //Items included in the foldout show Random if (showRandom) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); // Creates Break between items GUILayout.Label("Set Heights Between Random Values", EditorStyles.boldLabel); // Text label EditorGUILayout.PropertyField(randomHeightRange); //SerializedProperty to be edited if (GUILayout.Button("Random Heights")) //Generates Button { terrain.RandomTerrain(); //If button pressed will execute code } } showLoadHeights = EditorGUILayout.Foldout(showLoadHeights, "Load Heights"); // Items included in the foldout for setting terrain from image. if (showLoadHeights) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Load Heights From Texture", EditorStyles.boldLabel); EditorGUILayout.PropertyField(heightMapImage); EditorGUILayout.PropertyField(heightMapScale); if (GUILayout.Button("Load Texture")) { terrain.LoadTexture(); } } showPerlinNoise = EditorGUILayout.Foldout(showPerlinNoise, "Single Perlin Noise"); // Items included in the foldout for generating terrain from 2D Perlin noise if (showPerlinNoise) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("PerlinNoise", EditorStyles.boldLabel); EditorGUILayout.Slider(perlinXScale, 0, 1, new GUIContent("X Scale")); EditorGUILayout.Slider(perlinYScale, 0, 1, new GUIContent("Y Scale")); EditorGUILayout.IntSlider(perlinOffsetX, 0, 10000, new GUIContent("Offset X")); EditorGUILayout.IntSlider(perlinOffsetY, 0, 10000, new GUIContent("Offset Y")); EditorGUILayout.IntSlider(perlinOctaves, 1, 10, new GUIContent("Octaves")); EditorGUILayout.Slider(perlinPersistance, 1, 10, new GUIContent("Persistence")); EditorGUILayout.Slider(perlinHeightScale, 0, 1, new GUIContent("Height Scale")); if (GUILayout.Button("Perlin")) { terrain.Perlin(); } } showMultiplePerlin = EditorGUILayout.Foldout(showMultiplePerlin, "Multiple Perlin Noise"); // Items included in the foldout for generating terrain with multiple Perlin noises; if (showMultiplePerlin) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Multiple Perlin Noise", EditorStyles.boldLabel); perlinParameterTable = GUITableLayout.DrawTable(perlinParameterTable, perlinParameters); // creates a table which stores each perlin noise GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewPerlin(); } if (GUILayout.Button("-")) { terrain.RemovePerlin(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Multiple Perlin")) { terrain.MultiplePerlinTerrain(); } } showVoroni = EditorGUILayout.Foldout(showVoroni, "Voronoi"); // Items included in the foldout for generating a Voronoi mountain on the terrain if (showVoroni) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Voronoi", EditorStyles.boldLabel); EditorGUILayout.IntSlider(voronoiPeakCount, 1, 10, new GUIContent("Peak Count")); EditorGUILayout.Slider(voronoiFallOff, 0, 10, new GUIContent("Fall off")); EditorGUILayout.Slider(voronoiDropOff, 0, 10, new GUIContent("Drop off")); EditorGUILayout.Slider(voronoiMinHeight, 0, 1, new GUIContent("Min Height")); EditorGUILayout.Slider(voronoiMaxHeight, 0, 1, new GUIContent("Max Height")); EditorGUILayout.PropertyField(voronoiType); if (GUILayout.Button("Voronoi")) { terrain.Voronoi(); } } showMidPointDisplacement = EditorGUILayout.Foldout(showMidPointDisplacement, "Mid Point Displacement"); // Items included in the foldout for generating a Mid point displacement mountain on the terrain if (showMidPointDisplacement) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("MidPoint Displacement", EditorStyles.boldLabel); EditorGUILayout.PropertyField(MPHeightMin); EditorGUILayout.PropertyField(MPHeightMax); EditorGUILayout.PropertyField(MPHeightDampenerPower); EditorGUILayout.PropertyField(MPRoughness); if (GUILayout.Button("Mid Point Displacement")) { terrain.MidPointDisplacement(); } } showSmooth = EditorGUILayout.Foldout(showSmooth, "Smooth Terrain"); // Items included in the foldout for generating Smoother terrain if (showSmooth) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Smooth Terrain", EditorStyles.boldLabel); EditorGUILayout.IntSlider(SmoothAmount, 1, 10, new GUIContent("Smooth Amount")); if (GUILayout.Button("Smooth")) { terrain.Smooth(); } } showSplatMaps = EditorGUILayout.Foldout(showSplatMaps, "Splat Maps"); // Items included in the foldout for generating SplatMap Textures for terrain if (showSplatMaps) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Splat Map", EditorStyles.boldLabel); splatMapTable = GUITableLayout.DrawTable(splatMapTable, splatHeights); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewSplatHeight(); } if (GUILayout.Button("-")) { terrain.RemoveSplatHeight(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply SplatMaps")) { terrain.SplatMaps(); } } showHeights = EditorGUILayout.Foldout(showHeights, "Height Map"); //Items included in the foldout for generating a height map of the current terrain. if (showHeights) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Current Height Map", EditorStyles.boldLabel); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); int hmtSize = (int)(EditorGUIUtility.currentViewWidth - 100); GUILayout.Label(hmTexture, GUILayout.Width(hmtSize), GUILayout.Height(hmtSize)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Refresh", GUILayout.Width(hmtSize))) { float[,] heightMap = terrain.terrainData.GetHeights(0, 0, terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight); for (int y = 0; y < terrain.terrainData.heightmapHeight; y++) { for (int x = 0; x < terrain.terrainData.heightmapWidth; x++) { hmTexture.SetPixel(x, y, new Color(heightMap[x, y], heightMap[x, y], heightMap[x, y], 1)); } } hmTexture.Apply(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } showVegetation = EditorGUILayout.Foldout(showVegetation, "Vegetation"); //Items included in the foldout for generating the tree vegetation on the terrain if (showVegetation) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Vegetation", EditorStyles.boldLabel); EditorGUILayout.IntSlider(maxTrees, 0, 10000, new GUIContent("Maximum Trees")); EditorGUILayout.IntSlider(treeSpacing, 2, 20, new GUIContent("Tree Spacing")); vegetationTable = GUITableLayout.DrawTable(vegetationTable, vegatation); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewVegetation(); } if (GUILayout.Button("-")) { terrain.RemoveVegetation(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Vegetation")) { terrain.plantVegetation(); } } showDetail = EditorGUILayout.Foldout(showDetail, "Detail"); //Items included in the foldout for generating the details (e.g. grass) on the terrain if (showDetail) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Detail", EditorStyles.boldLabel); EditorGUILayout.IntSlider(maxDetails, 0, 10000, new GUIContent("Max Details")); EditorGUILayout.IntSlider(detailSpacing, 2, 20, new GUIContent("Detail Spacing")); DetailTable = GUITableLayout.DrawTable(DetailTable, details); terrain.GetComponent <Terrain>().detailObjectDistance = maxDetails.intValue; GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewDetails(); } if (GUILayout.Button("-")) { terrain.RemoveDetails(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Vegetation")) { terrain.AddDetails(); } } //Items included in the foldout for generating Water onto the map. showWater = EditorGUILayout.Foldout(showWater, "Water"); if (showWater) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Water", EditorStyles.boldLabel); EditorGUILayout.Slider(waterHeight, 0, 1, new GUIContent("Water Height")); EditorGUILayout.PropertyField(waterGO); if (GUILayout.Button("Add Water")) { terrain.Addwater(); } EditorGUILayout.PropertyField(shoreMaterial); if (GUILayout.Button("Add ShoreLine")) { terrain.DrawShoreLine(); } } //Items included in the foldout for enabling different types of erosion to occur on the terrain. showEroision = EditorGUILayout.Foldout(showEroision, "Erosion"); if (showEroision) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Erosion", EditorStyles.boldLabel); EditorGUILayout.PropertyField(ErosionType); EditorGUILayout.Slider(ErosionStrength, 0, 1, new GUIContent("Erosion Strength")); EditorGUILayout.Slider(erosionAmount, 0, 1, new GUIContent("Erosion Amount")); EditorGUILayout.IntSlider(Droplets, 0, 500, new GUIContent("Droplets")); EditorGUILayout.Slider(Solubility, 0.001f, 1, new GUIContent("Solubility")); EditorGUILayout.IntSlider(SpringsPerRiver, 0, 20, new GUIContent("Springs Per River")); EditorGUILayout.IntSlider(erosionSmoothAmount, 0, 10, new GUIContent("Smooth Amount")); if (GUILayout.Button("Erode")) { terrain.Erode(); } } //Items included in the foldout for generating clouds in the scene showClouds = EditorGUILayout.Foldout(showClouds, "Clouds"); if (showClouds) { EditorGUILayout.PropertyField(NumberOfClouds, new GUIContent("Number of Clouds")); EditorGUILayout.PropertyField(ParticlePerCloud, new GUIContent("Particles Per Cloud")); EditorGUILayout.PropertyField(CloudStartSize, new GUIContent("Cloud Particle Size")); EditorGUILayout.PropertyField(CloudSize, new GUIContent("Min Size")); EditorGUILayout.PropertyField(CloudMaxSize, new GUIContent("Max Size")); EditorGUILayout.PropertyField(CloudMaterial, true); EditorGUILayout.PropertyField(CloudShadowMaterial, true); EditorGUILayout.PropertyField(CloudColor, new GUIContent("Color")); EditorGUILayout.PropertyField(CloudLining, new GUIContent("Lining")); EditorGUILayout.PropertyField(MinSpeed, new GUIContent("Min Speed")); EditorGUILayout.PropertyField(MaxSpeed, new GUIContent("Max Speed")); EditorGUILayout.PropertyField(DistanceTravelled, new GUIContent("Distance Traveled")); if (GUILayout.Button("Generate Clouds")) { terrain.GenerateClouds(); } } // Creates the reset button EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); if (GUILayout.Button("Reset Terrain")) { terrain.ResetTerrain(); } //Scrollbar ending code EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { int wSize = (int)(EditorGUIUtility.currentViewWidth - 100); serializedObject.Update(); CustomTerrain terrain = (CustomTerrain)target; // Scrollbar starting code Rect r = EditorGUILayout.BeginVertical(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(r.width), GUILayout.Height(r.height)); EditorGUI.indentLevel++; EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showRandom = EditorGUILayout.Foldout(showRandom, "RandomGenProps"); if (showRandom) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Set Height Randomly Between Two Values", EditorStyles.boldLabel); EditorGUILayout.PropertyField(randomHeightRange); if (GUILayout.Button("Gen Random Heights")) { terrain.RandomTerrain(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showLoadHeights = EditorGUILayout.Foldout(showLoadHeights, "ImageGenProps"); if (showLoadHeights) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Load Height From Texture", EditorStyles.boldLabel); EditorGUILayout.PropertyField(heightMapImage); EditorGUILayout.PropertyField(heightMapScale); if (GUILayout.Button("Load Texture Heights")) { terrain.LoadTexture(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showPerlin = EditorGUILayout.Foldout(showPerlin, "PerlinGenProps"); if (showPerlin) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Set Height Based On Perlin Noise", EditorStyles.boldLabel); EditorGUILayout.Slider(perlinXScale, 0.0f, 1.0f, new GUIContent("X Scale")); EditorGUILayout.Slider(perlinYScale, 0.0f, 1.0f, new GUIContent("Y Scale")); EditorGUILayout.IntSlider(perlinOffsetX, 0, 10000, new GUIContent("X Offset")); EditorGUILayout.IntSlider(perlinOffsetY, 0, 10000, new GUIContent("Y Offset")); EditorGUILayout.IntSlider(perlinOctaves, 1, 10, new GUIContent("Octaves")); EditorGUILayout.Slider(perlinPersistance, 0.1f, 10.0f, new GUIContent("Persistance")); EditorGUILayout.Slider(perlinHeightScale, 0.0f, 1.0f, new GUIContent("Perlin Height Scale")); if (GUILayout.Button("Gen Perlin Heights")) { terrain.Perlin(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showMultiPerlin = EditorGUILayout.Foldout(showMultiPerlin, "MultiPerlinGenProps"); if (showMultiPerlin) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Set Height Based On Multiple Perlin Noise", EditorStyles.boldLabel); perlinParameterTable = GUITableLayout.DrawTable(perlinParameterTable, serializedObject.FindProperty("perlinParameters")); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewPerlin(); } if (GUILayout.Button("-")) { terrain.RemovePerlin(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Gen Multi Perlin Heights")) { terrain.MultiplePerlinTerrain(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showVoronoi = EditorGUILayout.Foldout(showVoronoi, "VoronoiGenProps"); if (showVoronoi) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Set Height Based On Voronoi Noise", EditorStyles.boldLabel); EditorGUILayout.IntSlider(voronoiPeaks, 1, 10, new GUIContent("Peaks")); EditorGUILayout.Slider(voronoiMinHeight, 0.0f, 1.0f, new GUIContent("Min Height")); EditorGUILayout.Slider(voronoiMaxHeight, 0.0f, 1.0f, new GUIContent("Max Height")); EditorGUILayout.Slider(voronoiFallOff, 0.0f, 10.0f, new GUIContent("Fall Off")); EditorGUILayout.Slider(voronoiDropOff, 0.0f, 10.0f, new GUIContent("Drop Off")); EditorGUILayout.PropertyField(voronoiType); if (GUILayout.Button("Gen Voronoi Heights")) { terrain.Voronoi(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showMPD = EditorGUILayout.Foldout(showMPD, "MPDGenProps"); if (showMPD) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Set Height Base On MPD ", EditorStyles.boldLabel); EditorGUILayout.PropertyField(MPDHeightMin); EditorGUILayout.PropertyField(MPDHeightMax); EditorGUILayout.PropertyField(MPDHeightDampenerPower); EditorGUILayout.PropertyField(MPDRoughness); if (GUILayout.Button("MPD")) { terrain.MPD(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showSplatMap = EditorGUILayout.Foldout(showSplatMap, "SplatMapProps"); if (showSplatMap) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Texture The Terrain With Splat Map", EditorStyles.boldLabel); splatMapTable = GUITableLayout.DrawTable(splatMapTable, serializedObject.FindProperty("splatHeights")); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewSplatHeight(); } if (GUILayout.Button("-")) { terrain.RemoveSplatHeight(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply SplatMap")) { terrain.SplatMaps(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showVegetation = EditorGUILayout.Foldout(showVegetation, "VegGenProps"); if (showVegetation) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Generate Vegetation", EditorStyles.boldLabel); EditorGUILayout.IntSlider(vegMaxTrees, 0, 10000, new GUIContent("Max Trees")); EditorGUILayout.IntSlider(vegTreeSpacing, 2, 20, new GUIContent("Tree Spacing")); vegetationTable = GUITableLayout.DrawTable(vegetationTable, serializedObject.FindProperty("vegetationList")); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewVegetation(); } if (GUILayout.Button("-")) { terrain.RemoveVegetation(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Generate Vegetation")) { terrain.PlaceVegetation(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showDetail = EditorGUILayout.Foldout(showDetail, "DetailGenProps"); if (showDetail) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Generate Detail", EditorStyles.boldLabel); EditorGUILayout.IntSlider(maxDetails, 0, 10000, new GUIContent("Max Detail")); terrain.GetComponent <Terrain>().detailObjectDistance = maxDetails.intValue; EditorGUILayout.IntSlider(detailSpacing, 2, 20, new GUIContent("Detail Spacing")); detailTable = GUITableLayout.DrawTable(detailTable, serializedObject.FindProperty("detailList")); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewDetails(); } if (GUILayout.Button("-")) { terrain.RemoveDetails(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Generate Details")) { terrain.PlaceDetails(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showWater = EditorGUILayout.Foldout(showWater, "WaterGenProps"); if (showWater) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Generate Water", EditorStyles.boldLabel); EditorGUILayout.Slider(waterHeight, 0.0f, 1.0f, new GUIContent("Water Height")); EditorGUILayout.PropertyField(waterGO); if (GUILayout.Button("Add Water")) { terrain.AddWater(); } EditorGUILayout.PropertyField(shoreLineMat); if (GUILayout.Button("Add Shore")) { terrain.DrawShoreLine(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showErosion = EditorGUILayout.Foldout(showErosion, "ErosionProps"); if (showErosion) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Erode Landscape", EditorStyles.boldLabel); EditorGUILayout.PropertyField(erosionType); EditorGUILayout.Slider(erosionStrength, 0.0f, 1.0f, new GUIContent("Erosion Strength")); EditorGUILayout.Slider(erosionAmount, 0.0f, 1.0f, new GUIContent("Erosion Amount")); EditorGUILayout.Slider(erosionSolubility, 0.001f, 1.0f, new GUIContent("Solubility")); EditorGUILayout.IntSlider(erosionDroplets, 0, 500, new GUIContent("Droplets")); EditorGUILayout.IntSlider(erosionsRiverSprings, 0, 20, new GUIContent("Springs Per River")); EditorGUILayout.IntSlider(erosionSmoothAmount, 0, 10, new GUIContent("Smooth Amount")); if (GUILayout.Button("Erode")) { terrain.Erode(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showClouds = EditorGUILayout.Foldout(showClouds, "CloudProps"); if (showClouds) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Generate Clouds In The Sky", EditorStyles.boldLabel); EditorGUILayout.PropertyField(numClouds, new GUIContent("Number of Clouds")); EditorGUILayout.PropertyField(particlesPerCloud, new GUIContent("Particles Per Cloud")); EditorGUILayout.PropertyField(cloudScaleMin, new GUIContent("Cloud Min Size")); EditorGUILayout.PropertyField(cloudScaleMax, new GUIContent("Cloud max Size")); EditorGUILayout.PropertyField(cloudMat, true); EditorGUILayout.PropertyField(cloudShadowMat, true); EditorGUILayout.PropertyField(cloudColor, new GUIContent("Color")); EditorGUILayout.PropertyField(cloudLining, new GUIContent("Lining")); EditorGUILayout.PropertyField(cloudStartSize, new GUIContent("Cloud Particle Size")); EditorGUILayout.PropertyField(cloudMinSpeed, new GUIContent("Min Speed")); EditorGUILayout.PropertyField(cloudMaxSpeed, new GUIContent("Max Speed")); EditorGUILayout.PropertyField(cloudRange, new GUIContent("Dst Travelled")); if (GUILayout.Button("Generate Clouds")) { terrain.GenerateClouds(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showSmooth = EditorGUILayout.Foldout(showSmooth, "SmoothProps"); if (showSmooth) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Smooth The Terrain", EditorStyles.boldLabel); EditorGUILayout.IntSlider(smoothAmount, 1, 10, new GUIContent("Smooth Amount")); if (GUILayout.Button("Smooth")) { terrain.SmoothTerrain(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.PropertyField(resetBeforeGen); if (GUILayout.Button("Reset Terrain")) { terrain.ResetTerrain(); } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showHeightMap = EditorGUILayout.Foldout(showHeightMap, "ShowHeightMap"); if (showHeightMap) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("View The Height Map", EditorStyles.boldLabel, GUILayout.Width(wSize / 2)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label(heightMapTexture, GUILayout.Width(wSize), GUILayout.Height(wSize)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Refresh", GUILayout.Width(wSize))) { RefreshHeightMapDisplay(terrain); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } //Scrollbar ending code EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { //Start serializedObject.Update(); //Start CustomTerrain terrain = (CustomTerrain)target; Rect r = EditorGUILayout.BeginVertical(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(r.width), GUILayout.Height(r.height)); EditorGUI.indentLevel++; EditorGUILayout.PropertyField(resetTerrain); showRandom = EditorGUILayout.Foldout(showRandom, "Random"); if (showRandom) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Set Heights Between Random Values", EditorStyles.boldLabel); EditorGUILayout.PropertyField(randomHeightRange); if (GUILayout.Button("Random Heights")) { terrain.RandomTerrain(); } } showLoadHeights = EditorGUILayout.Foldout(showLoadHeights, "Load Heights"); if (showLoadHeights) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Load Heights from Texture", EditorStyles.boldLabel); EditorGUILayout.PropertyField(heightMapImage); EditorGUILayout.PropertyField(heightMapScale); if (GUILayout.Button("Load Texture")) { terrain.LoadTexture(); } } showPerlinNoise = EditorGUILayout.Foldout(showPerlinNoise, "Single Perlin Noise"); if (showPerlinNoise) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Perlin Noise Scale", EditorStyles.boldLabel); EditorGUILayout.Slider(perlinXScale, 0, 1, new GUIContent("X Scale")); EditorGUILayout.Slider(perlinYScale, 0, 1, new GUIContent("Y Scale")); EditorGUILayout.IntSlider(perlinOffsetX, 0, 10000, new GUIContent("Offset X")); EditorGUILayout.IntSlider(perlinOffsetY, 0, 10000, new GUIContent("Offset Y")); EditorGUILayout.IntSlider(perlinOctaves, 1, 10, new GUIContent("Octaves")); EditorGUILayout.Slider(perlinPersistance, 0.1f, 10, new GUIContent("Persistance")); EditorGUILayout.Slider(perlinHeightScale, 0, 1, new GUIContent("Height Scale")); if (GUILayout.Button("Run Perlin Noise")) { terrain.Perlin(); } } showMultiplePerlin = EditorGUILayout.Foldout(showMultiplePerlin, "Multiple Perlin Noise"); if (showMultiplePerlin) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Mulitple Perlin Noise", EditorStyles.boldLabel); perlinParameterTable = GUITableLayout.DrawTable(perlinParameterTable, serializedObject.FindProperty("perlinParameters")); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewPerlin(); } if (GUILayout.Button("-")) { terrain.RemovePerlin(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Multiple Perlin")) { terrain.MultiplePerlinTerrain(); } } showVoronoi = EditorGUILayout.Foldout(showVoronoi, "Voronoi"); if (showVoronoi) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Voronoi", EditorStyles.boldLabel); EditorGUILayout.IntSlider(voronoiPeaks, 1, 10, new GUIContent("Peak Count")); EditorGUILayout.Slider(voronoiFallOff, 0, 10, new GUIContent("Falloff")); EditorGUILayout.Slider(voronoiDropOff, 0, 10, new GUIContent("Dropoff")); EditorGUILayout.Slider(voronoiMinHeight, 0, 1, new GUIContent("Min Height")); EditorGUILayout.Slider(voronoiMaxHeight, 0, 1, new GUIContent("Max Height")); EditorGUILayout.PropertyField(voronoiType); if (GUILayout.Button("Voronoi")) { terrain.Voronoi(); } } showMPD = EditorGUILayout.Foldout(showMPD, "Midpoint Displacement"); if (showMPD) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Mid Point Displacement", EditorStyles.boldLabel); EditorGUILayout.PropertyField(MPDheightMin); EditorGUILayout.PropertyField(MPDheightMax); EditorGUILayout.PropertyField(MPDheightDampenerPower); EditorGUILayout.PropertyField(MPDroughness); if (GUILayout.Button("Calculate Mid Point Displacement")) { terrain.MidPointDisplacement(); } } showSmooth = EditorGUILayout.Foldout(showSmooth, "Smooth Terrain"); if (showSmooth) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Smooth Terrain", EditorStyles.boldLabel); EditorGUILayout.IntSlider(smoothAmount, 1, 10, new GUIContent("smoothAmount")); if (GUILayout.Button("Smooth Terrain")) { terrain.Smooth(); } } showSplatMaps = EditorGUILayout.Foldout(showSplatMaps, "Splat Maps"); if (showSplatMaps) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Splat Maps", EditorStyles.boldLabel); splatMapTable = GUITableLayout.DrawTable(splatMapTable, serializedObject.FindProperty("splatHeights")); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewSplatHeight(); } if (GUILayout.Button("-")) { terrain.RemoveSplatHeight(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Splatmaps")) { terrain.SplatMaps(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showVeg = EditorGUILayout.Foldout(showVeg, "Vegetation"); if (showVeg) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Trees", EditorStyles.boldLabel); EditorGUILayout.IntSlider(maxTrees, 0, 10000, new GUIContent("Maximum Trees")); EditorGUILayout.IntSlider(treeSpacing, 2, 20, new GUIContent("Tree Spacing")); vegMapTable = GUITableLayout.DrawTable(vegMapTable, serializedObject.FindProperty("vegetation")); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewVegetation(); } if (GUILayout.Button("-")) { terrain.RemoveVegetation(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Vegetation")) { terrain.PlantVegetation(); } } showDetails = EditorGUILayout.Foldout(showDetails, "Details"); if (showDetails) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Detail", EditorStyles.boldLabel); EditorGUILayout.IntSlider(maxDetails, 0, 10000, new GUIContent("Maximum Details")); EditorGUILayout.IntSlider(detailSpacing, 2, 20, new GUIContent("Detail Spacing")); detailMapTable = GUITableLayout.DrawTable(detailMapTable, serializedObject.FindProperty("details")); terrain.GetComponent <Terrain>().detailObjectDistance = maxDetails.intValue; GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewDetails(); } if (GUILayout.Button("-")) { terrain.RemoveDetails(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Details")) { terrain.AddDetails(); } } showWater = EditorGUILayout.Foldout(showWater, "Water"); if (showWater) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Water", EditorStyles.boldLabel); EditorGUILayout.Slider(waterHeight, 0, 1, new GUIContent("Water Height")); EditorGUILayout.PropertyField(waterGameObject); if (GUILayout.Button("Add Water")) { terrain.AddWater(); } EditorGUILayout.PropertyField(shoreLineMaterial); if (GUILayout.Button("Draw Shoreline")) { terrain.DrawShoreline(); } } showErosion = EditorGUILayout.Foldout(showErosion, "Erosion"); if (showErosion) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Erosion", EditorStyles.boldLabel); EditorGUILayout.PropertyField(erosionType); EditorGUILayout.Slider(erosionStrength, 0, 1, new GUIContent("Erosion Strength")); EditorGUILayout.Slider(erosionAmount, 0, 1, new GUIContent("Erosion Amount")); EditorGUILayout.IntSlider(droplets, 0, 500, new GUIContent("Droplets")); EditorGUILayout.Slider(solubility, 0.01f, 1, new GUIContent("Solubility")); EditorGUILayout.IntSlider(springsPerRiver, 0, 20, new GUIContent("Springs Per River")); EditorGUILayout.IntSlider(erosionSmoothAmount, 0, 10, new GUIContent("Smooth Amount")); if (GUILayout.Button("Add Erosion")) { terrain.Erode(); } } showClouds = EditorGUILayout.Foldout(showClouds, "Clouds"); if (showClouds) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Clouds", EditorStyles.boldLabel); EditorGUILayout.PropertyField(numClouds, new GUIContent("Number of Clouds")); EditorGUILayout.PropertyField(particlesPerCloud, new GUIContent("Particles per Cloud")); EditorGUILayout.PropertyField(cloudStartSize, new GUIContent("Cloud Particle Size")); EditorGUILayout.PropertyField(cloudMinScale, new GUIContent("Min Size")); EditorGUILayout.PropertyField(cloudMaxScale, new GUIContent("Max Size")); EditorGUILayout.PropertyField(cloudMaterial, true); EditorGUILayout.PropertyField(cloudShadowMaterial, true); EditorGUILayout.PropertyField(cloudColor, new GUIContent("Cloud Color")); EditorGUILayout.PropertyField(cloudLining, new GUIContent("Lining Color")); EditorGUILayout.PropertyField(cloudMinSpeed, new GUIContent("Min Speed")); EditorGUILayout.PropertyField(cloudMaxSpeed, new GUIContent("Max Speed")); EditorGUILayout.PropertyField(cloudRange, new GUIContent("Distance Travelled")); if (GUILayout.Button("Add Clouds")) { terrain.GenerateClouds(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); showHeights = EditorGUILayout.Foldout(showHeights, "Height Map"); if (showHeights) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); int hmtSize = (int)(EditorGUIUtility.currentViewWidth - 100); GUILayout.Label(hmTexture, GUILayout.Width(hmtSize), GUILayout.Height(hmtSize)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Refresh", GUILayout.Width(hmtSize))) { float[,] heightMap = terrain.terrainData.GetHeights(0, 0, terrain.terrainData.heightmapResolution, terrain.terrainData.heightmapResolution); for (int y = 0; y < terrain.terrainData.alphamapHeight; y++) { for (int x = 0; x < terrain.terrainData.alphamapWidth; x++) { hmTexture.SetPixel(x, y, new Color(heightMap[x, y], heightMap[x, y], heightMap[x, y], 1)); } } hmTexture.Apply(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } if (GUILayout.Button("Reset Terrain")) { terrain.ResetTerrain(); } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); //End serializedObject.ApplyModifiedProperties(); //End }
public override void OnInspectorGUI() { serializedObject.Update(); CustomTerrain terrain = (CustomTerrain)target; EditorGUILayout.PropertyField(resetTerrain); showMultiplePerlin = EditorGUILayout.Foldout(showMultiplePerlin, "Multiple Perlin Noise"); if (showMultiplePerlin) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Multiple Perlin Noise", EditorStyles.boldLabel); perlinParameterTable = GUITableLayout.DrawTable( perlinParameterTable, serializedObject.FindProperty("perlinParameters")); EditorGUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewPerlin(); } if (GUILayout.Button("-")) { terrain.RemovePerlin(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Multiple Perlin")) { terrain.MultiplePerlinTerrain(); } } showPerlin = EditorGUILayout.Foldout(showPerlin, "Single Perlin Noise"); if (showPerlin) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Perlin Noise", EditorStyles.boldLabel); EditorGUILayout.Slider(perlinXScale, 0, 0.1f, new GUIContent("X Scale")); EditorGUILayout.Slider(perlinYScale, 0, 0.1f, new GUIContent("Y Scale")); EditorGUILayout.IntSlider(perlinOffsetX, 0, 10000, new GUIContent("X Offset")); EditorGUILayout.IntSlider(perlinOffsetY, 0, 10000, new GUIContent("Y Offset")); EditorGUILayout.IntSlider(perlinOctaves, 1, 10, new GUIContent("Octaves")); EditorGUILayout.Slider(perlinPersistance, 0f, 1f, new GUIContent("Persistance")); EditorGUILayout.Slider(perlinHeightScale, -1, 1, new GUIContent("Height Scale")); EditorGUILayout.Slider(perlinFreqMultiplier, 1, 5, new GUIContent("Freqency Multiplier")); if (GUILayout.Button("Generate and Apply Perlin Heights")) { terrain.Perlin(); } } showVoronoi = EditorGUILayout.Foldout(showVoronoi, "Voronoi"); if (showVoronoi) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Voronoi", EditorStyles.boldLabel); EditorGUILayout.IntSlider(voronoiPeakCount, 1, 10, new GUIContent("Number of Peaks")); EditorGUILayout.Slider(voronoiMinHeight, 0.0f, 1f, new GUIContent("Minimum Peak Height")); EditorGUILayout.Slider(voronoiMaxHeight, 0.0f, 1f, new GUIContent("Maximum Peak Height")); EditorGUILayout.Slider(voronoiFalloff, 0.0f, 10f, new GUIContent("Falloff")); EditorGUILayout.Slider(voronoiDropoff, 0.0f, 10f, new GUIContent("Dropoff")); EditorGUILayout.PropertyField(voronoiType); if (GUILayout.Button("Apply Voronoi")) { terrain.Voronoi(); } } showMPD = EditorGUILayout.Foldout(showMPD, "Midpoint Displacement"); if (showMPD) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Midpoint Displacement", EditorStyles.boldLabel); EditorGUILayout.Slider(MPDHeightMin, -20f, 0f, new GUIContent("Minimum Height")); EditorGUILayout.Slider(MPDHeightMax, 0f, 20f, new GUIContent("Maximum Height")); EditorGUILayout.Slider(MPDHeightDampenerPower, 0f, 10f, new GUIContent("Dampener Exponent")); EditorGUILayout.Slider(MPDRoughness, 0f, 10f, new GUIContent("Roughness")); if (GUILayout.Button("Run Midpoint Displacement")) { terrain.MidPointDisplacement(); } } showSmooth = EditorGUILayout.Foldout(showSmooth, "Smoothing"); if (showSmooth) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Smoothing Options", EditorStyles.boldLabel); EditorGUILayout.IntSlider(smoothingIterations, 1, 10, new GUIContent("Smoothing Iterations")); if (GUILayout.Button("Apply Smoothing")) { terrain.Smooth(smoothingIterations.intValue); } } showSplatMaps = EditorGUILayout.Foldout(showSplatMaps, "Splat Maps (Texturing)"); if (showSplatMaps) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Splat Maps", EditorStyles.boldLabel); splatMapTable = GUITableLayout.DrawTable(splatMapTable, serializedObject.FindProperty("splatheights")); EditorGUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewSplatHeight(); } if (GUILayout.Button("-")) { terrain.RemoveSplatHeight(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply SplatMaps")) { terrain.SplatMaps(); } } showVegetation = EditorGUILayout.Foldout(showVegetation, "Vegetation"); if (showVegetation) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Vegetation", EditorStyles.boldLabel); EditorGUILayout.IntSlider(maxTrees, 0, 50000, new GUIContent("Maximum Trees")); EditorGUILayout.IntSlider(treeSpacing, 2, 100, new GUIContent("Tree Spacing")); vegetationTable = GUITableLayout.DrawTable(vegetationTable, serializedObject.FindProperty("vegetation")); EditorGUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewVegetation(); } if (GUILayout.Button("-")) { terrain.RemoveVegetation(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Plant Vegetation")) { terrain.PlantVegetation(); } } showDetails = EditorGUILayout.Foldout(showDetails, "Detail"); if (showDetails) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Detail", EditorStyles.boldLabel); EditorGUILayout.IntSlider(maxDetails, 0, 10000, new GUIContent("Maximum Details")); EditorGUILayout.IntSlider(detailSpacing, 1, 100, new GUIContent("Detail Spacing")); detailsTable = GUITableLayout.DrawTable(detailsTable, serializedObject.FindProperty("details")); terrain.GetComponent <Terrain>().detailObjectDistance = maxDetails.intValue; EditorGUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewDetail(); } if (GUILayout.Button("-")) { terrain.RemoveDetail(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply Details")) { terrain.ApplyDetails(); } } showWater = EditorGUILayout.Foldout(showWater, "Water"); if (showWater) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Water", EditorStyles.boldLabel); EditorGUILayout.Slider(waterHeight, 0f, 1f, new GUIContent("Water Height")); EditorGUILayout.PropertyField(waterObject); if (GUILayout.Button("Add Water")) { terrain.AddWater(); } if (GUILayout.Button("Remove Water")) { terrain.RemoveWater(); } EditorGUILayout.PropertyField(shorelineMaterial); if (GUILayout.Button("Draw Shoreline")) { terrain.DrawShoreline(); } if (GUILayout.Button("Remove Shoreline")) { terrain.RemoveShoreline(); } } showErosion = EditorGUILayout.Foldout(showErosion, "Erosion"); if (showErosion) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Erosion", EditorStyles.boldLabel); EditorGUILayout.PropertyField(erosionType, new GUIContent("Erosion Type")); EditorGUILayout.Slider(erosionStrength, 0f, 1f, new GUIContent("Erosion Strength")); EditorGUILayout.Slider(erosionAmount, 0f, 1f, new GUIContent("Erosion Amount")); EditorGUILayout.IntSlider(droplets, 0, 5000, new GUIContent("Droplets")); EditorGUILayout.Slider(solubility, 0.001f, 1f, new GUIContent("Solubility")); EditorGUILayout.IntSlider(springsPerRiver, 0, 20, new GUIContent("Springs per River")); EditorGUILayout.Slider(windDirection, 0, 359, new GUIContent("Wind Direction")); EditorGUILayout.IntSlider(erosionIterations, 1, 20, new GUIContent("Erosion Iterations")); EditorGUILayout.IntSlider(erosionSmoothAmount, 0, 10, new GUIContent("Smooth Amount")); if (GUILayout.Button("Erode")) { terrain.Erode(); } } showClouds = EditorGUILayout.Foldout(showClouds, "Clouds"); if (showClouds) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Erosion", EditorStyles.boldLabel); EditorGUILayout.PropertyField(numberOfClouds, new GUIContent("Number of Clouds")); EditorGUILayout.PropertyField(particlesPerCloud, new GUIContent("Particles per Cloud")); EditorGUILayout.PropertyField(cloudParticleSize, new GUIContent("Particle Size")); EditorGUILayout.PropertyField(cloudSizeMin, new GUIContent("Cloud Size Min")); EditorGUILayout.PropertyField(cloudSizeMax, new GUIContent("Cloud Size Max")); EditorGUILayout.PropertyField(cloudMaterial, true); EditorGUILayout.PropertyField(cloudShadowMaterial, true); EditorGUILayout.PropertyField(cloudColor, new GUIContent("Color")); EditorGUILayout.PropertyField(cloudLiningColor, new GUIContent("Lining Color")); EditorGUILayout.PropertyField(cloudMinSpeed, new GUIContent("Min Speed")); EditorGUILayout.PropertyField(cloudMaxSpeed, new GUIContent("Max Speed")); EditorGUILayout.PropertyField(cloudDistancedTravelled, new GUIContent("Distance Travelled")); if (GUILayout.Button("Generate Clouds")) { terrain.GenerateClouds(); } if (GUILayout.Button("Remove Clouds")) { terrain.RemoveClouds(); } } showRandom = EditorGUILayout.Foldout(showRandom, "Random"); if (showRandom) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Set Heights Between Random Values", EditorStyles.boldLabel); EditorGUILayout.PropertyField(randomHeightRange); if (GUILayout.Button("Apply Random Heights")) { terrain.RandomTerrain(); } } showLoadHeights = EditorGUILayout.Foldout(showLoadHeights, "Load HeightMap Image"); if (showLoadHeights) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Load HeightMap Image", EditorStyles.boldLabel); EditorGUILayout.PropertyField(heightMapImage); EditorGUILayout.PropertyField(heightMapScale); if (GUILayout.Button("Load & Apply Texture")) { terrain.LoadHeightMapTexture(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); if (GUILayout.Button("Reset Terrain Height")) { terrain.ResetTerrainHeight(); } showHeightMap = EditorGUILayout.Foldout(showHeightMap, "Height Map"); if (showHeightMap) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); int wSize = (int)(EditorGUIUtility.currentViewWidth - 150); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label(terrain.heightMapTexture, GUILayout.Width(wSize), GUILayout.Height(wSize)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } serializedObject.ApplyModifiedProperties(); }