void OnFocus() { //Check what graphs are available. GraphPaths = GraphEditorUtils.GetAllGraphsInProject(); Func <string, GUIContent> selector = (s => new GUIContent(Path.GetFileNameWithoutExtension(s), s)); graphSelections = GraphPaths.Select(selector).ToArray(); //Keep the same graph selected even when the list of graphs changes. selectedGraph = GraphPaths.IndexOf((graph == null ? "" : graph.FilePath)); //If this graph was deleted, reset the editor. if (selectedGraph == -1) { unsavedStr = ""; graph = null; reconnectingOutput = -1; reconnectingInput = -2; reconnectingInput_Index = 0; activeWindowID = -1; } NewNodeOptions = NodeOptionsGenerator.GenerateList(); }
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); } } }
protected virtual void OnEnable() { graphPaths.Clear(); graphPaths = GraphEditorUtils.GetAllGraphsInProject(); Func <string, GUIContent> selector = (gp => new GUIContent(Path.GetFileNameWithoutExtension(gp), gp)); graphNameOptions = graphPaths.Select(selector).ToArray(); if (!isLoaded) { isLoaded = true; chosenGraphs.Clear(); if (graphPaths.Count > 0) { var graph = new Graph(graphPaths[0]); if (graph.Load().Length == 0) { chosenGraphs.Add(new GraphSelection() { Index = 0, Params = new GraphParamCollection(graph) }); } } } }
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; } } }
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("Shader Gen"); this.minSize = new Vector2(200.0f, 250.0f); selectedGraphIndex = 0; }
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)); } }
private void GUILeftArea() { GUILayout.Space(10.0f); GUILayout.Label("Graphs:"); int oldVal = selectedGraph; selectedGraph = EditorGUILayout.Popup(selectedGraph, graphSelections); if (selectedGraph != oldVal) { if (ConfirmLoseUnsavedChanges()) { Grph = new Graph(GraphPaths[selectedGraph]); string err = Grph.Load(); CamOffset = Grph.OutputPos.position - new Vector2(Mathf.RoundToInt(position.width * 0.5f), Mathf.RoundToInt(position.height * 0.5f)); if (err.Length > 0) { Debug.LogError("Error loading graph: " + err); } } 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 { Grph = g; CamOffset = Grph.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(Grph.FilePath); for (int i = 0; i < graphSelections.Length; ++i) { if (graphSelections[i].text == toFind) { selectedGraph = i; break; } } UpdatePreview(); } } } GUILayout.Space(30.0f); if (Grph != null && unsavedStr.Length > 0) { if (GUILayout.Button("Save Changes")) { string err = Grph.Save(); if (err.Length > 0) { Debug.LogError("Error saving graph: " + err); } unsavedStr = ""; } if (GUILayout.Button("Discard Changes")) { if (ConfirmLoseUnsavedChanges()) { string err = Grph.Load(); if (err.Length > 0) { Debug.LogError("Unable to reload graph: " + err); } else { UpdatePreview(); } } } } else { //Leave extra space for the buttons to appear once a change is made. GUILayout.Space(42.0f); } GUILayout.Space(35.0f); if (Grph != null) { GUILayout.Label("1D Hash:"); string oldHash = Grph.Hash1; Grph.Hash1 = GUILayout.TextField(Grph.Hash1); if (oldHash != Grph.Hash1) { if (!unsavedStr.Contains("1D hash func")) { unsavedStr += "1D hash func, "; } if (autoUpdatePreview) { UpdatePreview(); } } GUILayout.Space(10.0f); GUILayout.Label("2D Hash:"); oldHash = Grph.Hash2; Grph.Hash2 = GUILayout.TextField(Grph.Hash2); if (oldHash != Grph.Hash2) { if (!unsavedStr.Contains("2D hash func")) { unsavedStr += "2D hash func, "; } if (autoUpdatePreview) { UpdatePreview(); } } GUILayout.Space(10.0f); GUILayout.Label("3D Hash:"); oldHash = Grph.Hash3; Grph.Hash3 = GUILayout.TextField(Grph.Hash3); if (oldHash != Grph.Hash3) { if (!unsavedStr.Contains("3D hash func")) { unsavedStr += "3D hash func, "; } if (autoUpdatePreview) { UpdatePreview(); } } } GUILayout.Space(30.0f); //Noise previewing. if (Grph != 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)); GUI.DrawTextureWithTexCoords(texR, previewNoise, new Rect(0.0f, 1.0f, 1.0f, -1.0f)); } } //Update the title bar as well. if (Grph == null) { titleContent = new GUIContent("GPUG Editor"); } else if (unsavedStr.Length > 0) { titleContent = new GUIContent("*" + Path.GetFileNameWithoutExtension(Grph.FilePath) + "*"); } else { titleContent = new GUIContent(Path.GetFileNameWithoutExtension(Grph.FilePath)); } }