void OnEnable() { graphPaths.Clear(); graphPaths = GraphEditorUtils.GetAllGraphsInProject(); Func <string, GUIContent> selector = (gp => new GUIContent(Path.GetFileNameWithoutExtension(gp), gp)); graphNameOptions = graphPaths.Select(selector).ToArray(); this.titleContent = new GUIContent("Texture Gen"); this.minSize = new Vector2(200.0f, 270.0f); gParams = new GraphParamCollection(); GradientRamp_Colors = new List <Color>() { Color.black, Color.white }; GradientRamp_Times = new List <float>() { 0.0f, 1.0f }; SelectedGraphIndex = 0; if (graphPaths.Count > 0) { Graph g = new Graph(graphPaths[SelectedGraphIndex]); if (g.Load().Length == 0) { gParams = new GraphParamCollection(g); } } }
/// <summary> /// Updates the preview texture for this editor. /// </summary> /// <param name="regenerateShader"> /// If true, regenerates the graph's shader, which takes a lot longer. /// This should be true whenever the graph itself changes. /// </param> private void UpdatePreview(bool regenerateShader = true) { //Update params. var oldParams = graphParams; graphParams = new GPUGraph.GraphParamCollection(graph); graphParams.SetParams(oldParams); //Create shader. if (regenerateShader || cachedPreviewMat == null) { string shaderText = graph.GenerateShader("Graph editor temp shader", "rgb", 1.0f); Shader shader = ShaderUtil.CreateShaderAsset(shaderText); if (shader == null) { Debug.LogError("Shader: " + shaderText); } else { cachedPreviewMat = new Material(shader); } } //Create texture. if (previewNoise == null) { previewNoise = new Texture2D(256, 256, TextureFormat.RGBA32, false); } //Set params and generate. graphParams.SetParams(cachedPreviewMat); cachedPreviewMat.SetFloat(GraphUtils.Param_UVz, uvZ); GraphUtils.GenerateToTexture(cachedPreviewMat, previewNoise, true); }
void OnEnable() { graphPaths.Clear(); graphPaths = GraphEditorUtils.GetAllGraphsInProject(); Func <string, GUIContent> selector = (gp => new GUIContent(Path.GetFileNameWithoutExtension(gp), gp)); graphNameOptions = graphPaths.Select(selector).ToArray(); this.titleContent = new GUIContent("Terrain Gen"); this.minSize = new Vector2(200.0f, 250.0f); selectedGraphIndex = 0; if (graphPaths.Count > 0) { graph = new Graph(graphPaths[selectedGraphIndex]); if (graph.Load().Length == 0) { gParams = new GraphParamCollection(graph); GeneratePreview(); } else { graph = null; } } }
/// <summary> /// Does the GUI for this graph. /// Returns what changed. /// </summary> public ChangeTypes DoGUILayout(string label, List <string> graphPaths, GUIContent[] graphOptions) { var changes = ChangeTypes.None; GUILayout.BeginHorizontal(); GUILayout.Label(label); int oldIndex = Index; Index = EditorGUILayout.Popup(oldIndex, graphOptions); if (oldIndex != Index) { Graph g = new Graph(graphPaths[Index]); if (g.Load().Length > 0) { Index = oldIndex; } else { Params = new GraphParamCollection(g); changes = ChangeTypes.Everything; } } GUILayout.EndHorizontal(); GUILayout_TabIn(25.0f); if (Params != null && Params.ParamEditorGUI() && changes != ChangeTypes.Everything) { changes = ChangeTypes.Params; } GUILayout_TabOut(25.0f); return(changes); }
void OnEnable() { graphPaths.Clear(); graphPaths = GraphEditorUtils.GetAllGraphsInProject(); Func<string, GUIContent> selector = (gp => new GUIContent(Path.GetFileNameWithoutExtension(gp), gp)); graphNameOptions = graphPaths.Select(selector).ToArray(); this.titleContent = new GUIContent("Terrain Gen"); this.minSize = new Vector2(200.0f, 250.0f); gParams = new GraphParamCollection(); selectedGraphIndex = 0; if (graphPaths.Count > 0) { Graph g = new Graph(graphPaths[selectedGraphIndex]); if (g.Load().Length == 0) { gParams = new GraphParamCollection(g); } } }
/// <summary> /// Generates both textures and saves them to the given file paths. /// Returns whether the operation succeeded. /// </summary> private bool GenerateTextures(string texPath, string normalTexPath = null) { //The base data set should be large enough for both textures. int baseDataSizeX = X, baseDataSizeY = Y, baseDataSizeZ = Z; if (GenerateNormals) { baseDataSizeX = Math.Max(baseDataSizeX, Normals_X); baseDataSizeY = Math.Max(baseDataSizeY, Normals_Y); baseDataSizeZ = Math.Max(baseDataSizeZ, Normals_Z); } Graph graph = LoadGraph(); GraphParamCollection graphParams = GraphParams; //Generate the initial data. float[,,] baseData = GraphEditorUtils.GenerateToArray(graph, graphParams, baseDataSizeX, baseDataSizeY, baseDataSizeZ); //Generate the value texture. float[,,] valueTexData = baseData.ResampleFull(Mathf.Lerp, X, Y, Z); Gradient colorGradient = MakeGradient(); Color[] valueTexPixels = new Color[X * Y * Z]; for (int z = 0; z < Z; ++z) { for (int y = 0; y < Y; ++y) { for (int x = 0; x < X; ++x) { float value = valueTexData[x, y, z]; int index = x + (y * X) + (z * X * Y); valueTexPixels[index] = colorGradient.Evaluate(value); } } } Texture3D valueTex = new Texture3D(X, Y, Z, TextureFormat.ARGB32, false); valueTex.wrapMode = Wrapping; valueTex.filterMode = Filtering; valueTex.SetPixels(valueTexPixels); valueTex.Apply(UseMipmaps, !LeaveReadable); AssetDatabase.CreateAsset(valueTex, StringUtils.GetRelativePath(texPath, "Assets")); //Generate the normals texture. if (normalTexPath == null) { return(true); } float[,,] normalsValueData = baseData.ResampleFull(Mathf.Lerp, Normals_X, Normals_Y, Normals_Z); Color[] normalsPixels = new Color[Normals_X * Normals_Y * Normals_Z]; for (int z = 0; z < Normals_Z; ++z) { for (int y = 0; y < Normals_Y; ++y) { for (int x = 0; x < Normals_X; ++x) { //The first digit is the X, the second is the Y, the third is the Z. float _000, _100, _010, _110, _001, _101, _011, _111; normalsValueData.Sample(x, y, z, true, out _000, out _100, out _010, out _110, out _001, out _101, out _011, out _111); Vector3 gradient = new Vector3(); gradient.x = (_100 - _000) + (_110 - _010) + (_101 - _001) + (_111 - _011); gradient.y = (_010 - _000) + (_110 - _100) + (_011 - _001) + (_111 - _101); gradient.z = (_001 - _000) + (_101 - _100) + (_011 - _010) + (_111 - _110); //Normalize. if (gradient == Vector3.zero) { gradient = Vector3.up; } else { gradient = gradient.normalized; } //Pack into a color. int index = x + (y * Normals_X) + (z * Normals_X * Normals_Y); normalsPixels[index] = new Color(0.5f + (0.5f * gradient.x), 0.5f + (0.5f * gradient.y), 0.5f + (0.5f * gradient.z)); } } } Texture3D normalsTex = new Texture3D(Normals_X, Normals_Y, Normals_Z, Normals_Format, Normals_UseMipmaps); normalsTex.wrapMode = Normals_Wrapping; normalsTex.filterMode = Normals_Filtering; normalsTex.SetPixels(normalsPixels); normalsTex.Apply(Normals_UseMipmaps, !Normals_LeaveReadable); AssetDatabase.CreateAsset(normalsTex, StringUtils.GetRelativePath(normalTexPath, "Assets")); return(true); }
private void GUILeftArea() { GUILayout.Space(10.0f); GUILayout.Label("Graphs:"); int oldVal = selectedGraph; selectedGraph = EditorGUILayout.Popup(selectedGraph, graphSelections); if (selectedGraph != oldVal) { if (ConfirmLoseUnsavedChanges()) { graph = new Graph(GraphPaths[selectedGraph]); string err = graph.Load(); CamOffset = graph.OutputPos.position - new Vector2(Mathf.RoundToInt(position.width * 0.5f), Mathf.RoundToInt(position.height * 0.5f)); if (err.Length > 0) { graphParams = new GPUGraph.GraphParamCollection(graph); Debug.LogError("Error loading graph: " + err); } else { graphParams = new GraphParamCollection(graph); } UpdatePreview(); } else { selectedGraph = oldVal; } } GUILayout.Space(35.0f); if (GUILayout.Button("New Graph") && ConfirmLoseUnsavedChanges()) { string savePath = EditorUtility.SaveFilePanelInProject("Choose Graph location", "MyGraph.gpug", "gpug", "Choose where to save the graph."); if (savePath != "") { Graph g = new Graph(savePath); string err = g.Save(); if (err.Length > 0) { EditorUtility.DisplayDialog("Error saving new graph", "Error saving graph " + g.FilePath + ": " + err, "OK"); } else { graph = g; CamOffset = graph.OutputPos.position - new Vector2(Mathf.RoundToInt(position.width * 0.5f), Mathf.RoundToInt(position.height * 0.5f)); GraphPaths = GraphEditorUtils.GetAllGraphsInProject(); NewNodeOptions = NodeOptionsGenerator.GenerateList(); Func <string, GUIContent> selector = (s => new GUIContent(Path.GetFileNameWithoutExtension(s), s)); graphSelections = GraphPaths.Select(selector).ToArray(); selectedGraph = -1; string toFind = Path.GetFileNameWithoutExtension(graph.FilePath); for (int i = 0; i < graphSelections.Length; ++i) { if (graphSelections[i].text == toFind) { selectedGraph = i; break; } } UpdatePreview(); } } } GUILayout.Space(30.0f); if (graph != null && unsavedStr.Length > 0) { if (GUILayout.Button("Save Changes")) { string err = graph.Save(); if (err.Length > 0) { Debug.LogError("Error saving graph: " + err); } unsavedStr = ""; } if (GUILayout.Button("Discard Changes")) { if (ConfirmLoseUnsavedChanges()) { string err = graph.Load(); if (err.Length > 0) { graphParams = new GPUGraph.GraphParamCollection() { FloatParams = new List <GPUGraph.FloatParamInfo>(), Tex2DParams = new List <GPUGraph.Texture2DParamInfo>(), }; Debug.LogError("Unable to reload graph: " + err); } else { graphParams = new GraphParamCollection(graph); UpdatePreview(); } } } } else { //Leave extra space for the buttons to appear once a change is made. GUILayout.Space(42.0f); } GUILayout.Space(35.0f); //Noise previewing. if (graph != null) { bool oldAutoUpdate = autoUpdatePreview; autoUpdatePreview = GUILayout.Toggle(autoUpdatePreview, "Auto-Update Preview"); if (autoUpdatePreview && !oldAutoUpdate) { UpdatePreview(); } if (!autoUpdatePreview) { if (GUILayout.Button("Update Preview")) { UpdatePreview(); } } if (previewNoise != null) { //Flip the image vertically for unity GUI. Rect texR = EditorGUILayout.GetControlRect(GUILayout.Width(previewNoise.width), GUILayout.Height(previewNoise.height)); EditorGUI.DrawPreviewTexture(texR, previewNoise); //Draw a slider for the UV.z coordinate. GUILayout.BeginHorizontal(); { float oldUVz = uvZ; GUILayout.Label("UV.z coord:"); GUILayout.Space(10.0f); GUILayout.Label("0"); uvZ = GUILayout.HorizontalSlider(uvZ, 0.0f, uvZMax, GUILayout.Width(80.0f)); uvZMax = EditorGUILayout.FloatField(uvZMax, GUILayout.Width(25.0f)); GUILayout.FlexibleSpace(); if (oldUVz != uvZ) { UpdatePreview(false); } } GUILayout.EndHorizontal(); //Edit parameters. EditorGUI.BeginChangeCheck(); for (int i = 0; i < graphParams.FloatParams.Count; ++i) { var param = graphParams.FloatParams[i]; GUILayout.BeginHorizontal(); GUILayout.Label(param.Name); if (param.IsSlider) { param.DefaultValue = GUILayout.HorizontalSlider(Mathf.Lerp(param.SliderMin, param.SliderMax, param.DefaultValue), param.SliderMin, param.SliderMax, GUILayout.ExpandWidth(true), GUILayout.MinWidth(80.0f)); param.DefaultValue = Mathf.InverseLerp(param.SliderMin, param.SliderMax, param.DefaultValue); GUILayout.FlexibleSpace(); } else { param.DefaultValue = EditorGUILayout.DelayedFloatField(param.DefaultValue); } GUILayout.EndHorizontal(); graphParams.FloatParams[i] = param; } for (int i = 0; i < graphParams.Tex2DParams.Count; ++i) { var param = graphParams.Tex2DParams[i]; GUILayout.BeginHorizontal(); GUILayout.Label(param.Name); param.DefaultVal = (Texture2D)EditorGUILayout.ObjectField(param.Name, param.DefaultVal, typeof(Texture2D), false); GUILayout.EndHorizontal(); graphParams.Tex2DParams[i] = param; } if (EditorGUI.EndChangeCheck()) { UpdatePreview(false); } } } //Update the title bar as well. if (graph == null) { titleContent = new GUIContent("GPUG Editor"); } else if (unsavedStr.Length > 0) { titleContent = new GUIContent("*" + Path.GetFileNameWithoutExtension(graph.FilePath) + "*"); } else { titleContent = new GUIContent(Path.GetFileNameWithoutExtension(graph.FilePath)); } }
void OnGUI() { GUILayout.Space(10.0f); X = EditorGUILayout.IntField("Width", X); Y = EditorGUILayout.IntField("Height", Y); GUILayout.Space(15.0f); GUILayout.Label("Gradient"); GUILayout.BeginHorizontal(); GUILayout.Space(15.0f); GUILayout.BeginVertical(); for (int i = 0; i < GradientRamp_Colors.Count; ++i) { GUILayout.BeginHorizontal(); GradientRamp_Colors[i] = EditorGUILayout.ColorField(GradientRamp_Colors[i]); if (i > 0) { GradientRamp_Times[i] = EditorGUILayout.Slider(GradientRamp_Times[i], 0.0f, 1.0f); } if (i > 0 && GUILayout.Button("+")) { GradientRamp_Colors.Insert(i, GradientRamp_Colors[i]); GradientRamp_Times.Insert(i, GradientRamp_Times[i] - 0.00000001f); } if (i > 0 && GradientRamp_Colors.Count > 2 && GUILayout.Button("-")) { GradientRamp_Colors.RemoveAt(i); GradientRamp_Times.RemoveAt(i); i -= 1; } GUILayout.EndHorizontal(); if (i > 0 && GradientRamp_Times[i] < GradientRamp_Times[i - 1]) { GradientRamp_Times[i] = GradientRamp_Times[i - 1] + 0.000001f; } else if (i < GradientRamp_Colors.Count - 1 && GradientRamp_Times[i] > GradientRamp_Times[i + 1]) { GradientRamp_Times[i] = GradientRamp_Times[i + 1] - 0.00001f; } } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(15.0f); GUILayout.BeginHorizontal(); GUILayout.Label("Graph:"); int oldIndex = SelectedGraphIndex; SelectedGraphIndex = EditorGUILayout.Popup(SelectedGraphIndex, graphNameOptions); if (oldIndex != SelectedGraphIndex) { Graph g = new Graph(graphPaths[SelectedGraphIndex]); if (g.Load().Length == 0) { SelectedGraphIndex = oldIndex; } else { gParams = new GraphParamCollection(g); } } GUILayout.EndHorizontal(); GUILayout.Space(10.0f); //Show some GUI elements for changing the parameters. if (graphPaths.Count > 0) { gParams.ParamEditorGUI(); } GUILayout.Space(10.0f); //If a graph is selected, display a button to generate the texture. if (graphPaths.Count > 0) { if (GUILayout.Button("Generate Texture")) { string savePath = EditorUtility.SaveFilePanel("Choose where to save the texture.", Application.dataPath, "MyTex.png", "png"); if (savePath.Length > 0) { //Load the graph. Graph g = new Graph(graphPaths[SelectedGraphIndex]); if (g.Load().Length > 0) { return; } //Render the gradient ramp to a texture, // then render the graph's noise to a texture. Gradient grd = new Gradient(); grd.SetKeys(GradientRamp_Colors.Select((c, i) => new GradientColorKey(c, GradientRamp_Times[i])).ToArray(), new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f) }); Texture2D tex = GraphEditorUtils.GenerateToTexture(g, new GraphParamCollection(g, gParams), X, Y, grd); if (tex == null) { return; } //Write out the texture as a PNG. try { File.WriteAllBytes(savePath, tex.EncodeToPNG()); } catch (Exception e) { Debug.LogError("Unable to save texture to file: " + e.Message); } //Now that we're finished, clean up. AssetDatabase.ImportAsset(StringUtils.GetRelativePath(savePath, "Assets")); //Finally, open explorer to show the user the texture. if (Application.platform == RuntimePlatform.WindowsEditor) { System.Diagnostics.Process.Start("explorer.exe", "/select," + StringUtils.FixDirectorySeparators(savePath)); } else if (Application.platform == RuntimePlatform.OSXEditor) { try { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = "open"; proc.StartInfo.Arguments = "-n -R \"" + StringUtils.FixDirectorySeparators(savePath) + "\""; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardError = false; proc.StartInfo.RedirectStandardOutput = false; proc.ErrorDataReceived += (s, a) => Debug.Log(a.Data); if (proc.Start()) { proc.BeginErrorReadLine(); proc.BeginOutputReadLine(); } else { Debug.LogError("Error opening Finder to show texture file"); } } catch (Exception e) { Debug.LogError("Error opening Finder to show texture file: " + e.Message); } } } } } else { GUILayout.Space(15.0f); GUILayout.Label("No graph files detected in the project!"); } }
void OnGUI() { GUILayout.Space(10.0f); if (Selection.activeGameObject == null || Selection.activeGameObject.GetComponent <Terrain>() == null) { EditorGUILayout.LabelField("No terrain is selected in the editor."); } else { //Graph selection. GUILayout.BeginHorizontal(); GUILayout.Label("Graph:"); int oldIndex = selectedGraphIndex; selectedGraphIndex = EditorGUILayout.Popup(selectedGraphIndex, graphNameOptions); if (oldIndex != selectedGraphIndex) { Graph g = new Graph(graphPaths[selectedGraphIndex]); if (g.Load().Length == 0) { selectedGraphIndex = oldIndex; } else { gParams = new GraphParamCollection(g); } } GUILayout.EndHorizontal(); GUILayout.Space(15.0f); //Graph params. if (graphPaths.Count > 0) { gParams.ParamEditorGUI(); } GUILayout.Space(15.0f); //Other params. EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Height scale:"); heightScale = EditorGUILayout.FloatField(heightScale); EditorGUILayout.EndHorizontal(); GUILayout.Space(15.0f); //Button to generate heightmap. if (graphPaths.Count > 0) { if (GUILayout.Button("Generate Heightmap")) { Generate(); } } else { GUILayout.Space(15.0f); GUILayout.Label("No graph files detected in the project!"); } } }
private void OnGUI() { GUILayout.Space(15.0f); //Choose the graph to use. GUILayout.BeginHorizontal(); GUILayout.Label("Graph:"); int oldIndex = SelectedGraphIndex; SelectedGraphIndex = EditorGUILayout.Popup(SelectedGraphIndex, graphNameOptions); if (oldIndex != SelectedGraphIndex) { Graph g = new Graph(graphPaths[SelectedGraphIndex]); if (g.Load().Length > 0) { SelectedGraphIndex = oldIndex; } else { gParams = new GraphParamCollection(g); } GetPreview(true); } GUILayout.EndHorizontal(); GUILayout.Space(10.0f); OnGUI_BelowGraphSelection(); //Choose the color gradient. GUILayout.Label("Gradient"); GUILayout.BeginHorizontal(); GUILayout.Space(15.0f); GUILayout.BeginVertical(); for (int i = 0; i < GradientRamp_Colors.Count; ++i) { GUILayout.BeginHorizontal(); //Edit the color value. EditorGUI.BeginChangeCheck(); GradientRamp_Colors[i] = EditorGUILayout.ColorField(GradientRamp_Colors[i]); if (i > 0) { GradientRamp_Times[i] = EditorGUILayout.Slider(GradientRamp_Times[i], 0.0f, 1.0f); } if (EditorGUI.EndChangeCheck()) { GetPreview(true); } //Button to insert a new element. if (i > 0 && GUILayout.Button("+")) { GradientRamp_Colors.Insert(i, GradientRamp_Colors[i]); GradientRamp_Times.Insert(i, GradientRamp_Times[i] - 0.00000001f); GetPreview(true); } //Button to remove this element. if (i > 0 && GradientRamp_Colors.Count > 2 && GUILayout.Button("-")) { GradientRamp_Colors.RemoveAt(i); GradientRamp_Times.RemoveAt(i); i -= 1; GetPreview(true); } GUILayout.EndHorizontal(); //Make sure elements are in order. if (i > 0 && GradientRamp_Times[i] < GradientRamp_Times[i - 1]) { GradientRamp_Times[i] = GradientRamp_Times[i - 1] + 0.000001f; GetPreview(true); } else if (i < GradientRamp_Colors.Count - 1 && GradientRamp_Times[i] > GradientRamp_Times[i + 1]) { GradientRamp_Times[i] = GradientRamp_Times[i + 1] - 0.00001f; GetPreview(true); } } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(15.0f); OnGUI_BelowGradientAboveParams(); //Edit the graph's parameters. GUILayout.Label("Graph Parameters:"); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(); { if (graphPaths.Count > 0 && gParams.ParamEditorGUI()) { GetPreview(false); } } GUILayout.EndVertical(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(10.0f); OnGUI_AboveGenerationButton(); //Show the preview texture. if (previewTex != null) { //Preview scale slider. GUILayout.BeginHorizontal(); { GUILayout.Label("Preview Scale"); //Use a nonlinear scale for the slider. float t = Mathf.Log10(previewScale); float resultT = GUILayout.HorizontalSlider(t, -2.0f, 2.0f, GUILayout.Width(position.width - 40.0f)); previewScale = Mathf.Pow(10.0f, resultT); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { //Slider for preview UV z. GUILayout.BeginVertical(); { float oldZ = previewUVz; GUILayout.Label("Z"); previewUVzMax = EditorGUILayout.FloatField(previewUVzMax, GUILayout.Width(20.0f)); previewUVz = GUILayout.VerticalSlider(previewUVz, previewUVzMin, previewUVzMax, GUILayout.Height(previewTex.height * previewScale - (15.0f * 3))); previewUVzMin = EditorGUILayout.FloatField(previewUVzMin, GUILayout.Width(20.0f)); if (oldZ != previewUVz) { GetPreview(false); } } GUILayout.EndVertical(); Rect texPos = EditorGUILayout.GetControlRect(GUILayout.Width(previewTex.width * previewScale), GUILayout.Height(previewTex.height * previewScale)); EditorGUI.DrawPreviewTexture(texPos, previewTex); GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); } //If a graph is selected, display a button to generate the texture. if (graphPaths.Count > 0) { if (GUILayout.Button("Generate Texture")) { GenerateTexture(); } } else { GUILayout.Space(15.0f); GUILayout.Label("No graph files detected in the project!"); } }
void OnGUI() { GUILayout.Space(10.0f); scrollPos = GUILayout.BeginScrollView(scrollPos); if (Selection.activeGameObject == null || Selection.activeGameObject.GetComponent <Terrain>() == null) { EditorGUILayout.LabelField("No terrain is selected in the editor."); } else { //Graph selection. GUILayout.BeginHorizontal(); GUILayout.Label("Graph:"); int oldIndex = selectedGraphIndex; selectedGraphIndex = EditorGUILayout.Popup(selectedGraphIndex, graphNameOptions); if (oldIndex != selectedGraphIndex) { var newGraph = new Graph(graphPaths[selectedGraphIndex]); var errMsg = newGraph.Load(); if (errMsg.Length > 0) { Debug.LogError(errMsg); selectedGraphIndex = oldIndex; } else { gParams = new GraphParamCollection(newGraph); graph = newGraph; } } GUILayout.EndHorizontal(); GUILayout.Space(15.0f); //Graph params. if (graphPaths.Count > 0) { gParams.ParamEditorGUI(); } GUILayout.Space(15.0f); //Other params. EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Height scale:"); heightScale = EditorGUILayout.FloatField(heightScale); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); uvz = EditorGUILayout.Slider("UV.z", uvz, 0, 1); EditorGUILayout.EndHorizontal(); GUILayout.Space(15.0f); //Button to generate heightmap. if (graphPaths.Count > 0) { if (GUILayout.Button("Generate Heightmap")) { Generate(); } } else { GUILayout.Space(15.0f); GUILayout.Label("No graph files detected in the project!"); } //Preview texture. if (GUILayout.Button("Update Preview")) { GeneratePreview(); } if (previewTex != null) { GUILayout.Box(previewTex, GUILayout.Width(256), GUILayout.Height(256)); } } GUILayout.EndScrollView(); }
void OnGUI() { GUILayout.Space(10.0f); if (Selection.activeGameObject == null || Selection.activeGameObject.GetComponent<Terrain>() == null) { EditorGUILayout.LabelField("No terrain is selected in the editor."); } else { //Graph selection. GUILayout.BeginHorizontal(); GUILayout.Label("Graph:"); int oldIndex = selectedGraphIndex; selectedGraphIndex = EditorGUILayout.Popup(selectedGraphIndex, graphNameOptions); if (oldIndex != selectedGraphIndex) { Graph g = new Graph(graphPaths[selectedGraphIndex]); if (g.Load().Length == 0) { selectedGraphIndex = oldIndex; } else { gParams = new GraphParamCollection(g); } } GUILayout.EndHorizontal(); GUILayout.Space(15.0f); //Graph params. if (graphPaths.Count > 0) { gParams.ParamEditorGUI(); } GUILayout.Space(15.0f); //Other params. EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Height scale:"); heightScale = EditorGUILayout.FloatField(heightScale); EditorGUILayout.EndHorizontal(); GUILayout.Space(15.0f); //Button to generate heightmap. if (graphPaths.Count > 0) { if (GUILayout.Button("Generate Heightmap")) { Generate(); } } else { GUILayout.Space(15.0f); GUILayout.Label("No graph files detected in the project!"); } } }