public PWGraph Draw(Rect window, PWGraph graph) { EditorGUI.DrawRect(new Rect(0, 0, window.width, window.height), PWColorTheme.defaultBackgroundColor); presetScrollPos = EditorGUILayout.BeginScrollView(presetScrollPos); { EditorGUILayout.LabelField("Procedural Worlds"); //Load graph button: EditorGUILayout.BeginHorizontal(); { var newGraph = DrawGraphInput(graph); if (newGraph.GetType() == graph.GetType()) { graph = newGraph; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { DrawSelector(graph); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); return(graph); }
void SaveGraph(PWGraph graph) { string defaultPath = Application.dataPath + "/ProceduralWorlds/Editor/Resources/GraphPresets/"; string path = EditorUtility.SaveFilePanel("Save " + graph.name, defaultPath, graph.name, "txt"); if (String.IsNullOrEmpty(path)) { return; } graph.Export(path); //if the exported graph is inside the asset folder if (path.Contains(Application.dataPath)) { string relativePath = "Assets/" + path.Substring(Application.dataPath.Length + 1); AssetDatabase.Refresh(); var graphTextAsset = AssetDatabase.LoadAssetAtPath(relativePath, typeof(TextAsset)); ProjectWindowUtil.ShowCreatedAsset(graphTextAsset); } }
//called only once, when the node is created public void Initialize(PWGraph graph) { if (debug) { Debug.LogWarning("Node " + GetType() + "Initialize !"); } //generate "unique" id for node: byte[] bytes = System.Guid.NewGuid().ToByteArray(); id = (int)bytes[0] | (int)bytes[1] << 8 | (int)bytes[2] << 16 | (int)bytes[3] << 24; //set the node name: name = PWNodeTypeProvider.GetNodeName(GetType()); //set the name of the scriptableObject base.name = name; //set the graph reference: graphRef = graph; //Initialize the rest of the node OnAfterNodeAndGraphDeserialized(false); //call virtual NodeCreation method OnNodeCreation(); }
public static void Open <T>(PWGraph graph) where T : PWGraphEditor { PWGraphEditor editor = EditorWindow.GetWindow <T>(); editor.LoadGraph(graph); editor.Show(); }
public void OnAfterGraphDeserialize(PWGraph graph) { this.graphRef = graph; if (isEnabled) { OnAfterNodeAndGraphDeserialized(); } }
void GraphLoadedCallback(PWGraph graph) { if (graph == null) { return; } settingsBar.onDraw = DrawBiomeSettingsBar; }
public void LoadGraph(PWGraph graph) { if (this.graph != null) { UnloadGraph(false); } this.oldGraphType = graph.GetType(); this.graph = graph; graph.assetFilePath = AssetDatabase.GetAssetPath(graph); //attach to graph events graph.OnNodeAdded += NodeAddedCallback; graph.OnNodeRemoved += NodeRemovedCallback; graph.OnLinkCreated += LinkCreatedCallback; graph.OnLinkRemoved += LinkRemovedCallback; graph.OnPostLinkCreated += PostLinkCreatedCallback; graph.OnGraphStructureChanged += GraphStructureChangedCallback; //set the skin for the node style initialization GUI.skin = PWGUISkin; if (!styleLoaded) { LoadStyles(); } //update graph in views: optionBar = new PWGraphOptionBar(graph); nodeSelectorBar = new PWGraphNodeSelectorBar(graph); settingsBar = new PWGraphSettingsBar(graph); optionBar.LoadStyles(); nodeSelectorBar.LoadStyles(); settingsBar.LoadStyles(); if (!graph.initialized) { graph.Initialize(); graph.OnEnable(); SaveGraph(); } if (OnGraphChanged != null) { OnGraphChanged(graph); } graph.Process(); }
void RenderGraphNotFound() { EditorGUILayout.LabelField("Graph not found, ouble click on a graph asset file to a graph to open it"); if (oldGraphType != null) { PWGraph newGraph = EditorGUILayout.ObjectField(null, oldGraphType, false) as PWGraph; if (newGraph != null) { LoadGraph(newGraph); } } }
void DrawSelector(PWGraph graph) { GUILayout.FlexibleSpace(); EditorGUILayout.BeginVertical(); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); { GUILayout.FlexibleSpace(); int i = 0; string lastheader = null; EditorGUILayout.BeginHorizontal(); foreach (var presetCell in presetCellList) { if (lastheader != presetCell.header) { EditorGUILayout.EndHorizontal(); onDrawHeader(presetCell.header); EditorGUILayout.BeginHorizontal(); i = 0; } if (i != 0 && (i % maxColumnCells) == 0) { EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); } onDrawCell(presetCell); lastheader = presetCell.header; i++; } EditorGUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); EditorGUILayout.EndVertical(); GUILayout.FlexibleSpace(); }
void RemoveNodeLinkAsserts(PWGraph graph) { var add1 = graph.FindNodeByName("add1"); var add2 = graph.FindNodeByName("add2"); var add3 = graph.FindNodeByName("add3"); var slider = graph.FindNodeByName("slider"); var constant = graph.FindNodeByName("constant"); var debug2 = graph.FindNodeByName("debug2"); Assert.That(slider.GetOutputLinks().Count() == 1); Assert.That(slider.GetOutputLinks().First().toNode == add1); Assert.That(constant.GetOutputLinks().Count() == 1); Assert.That(constant.GetOutputLinks().First().toNode == add3); Assert.That(debug2.GetInputLinks().Count() == 0); foreach (var link in graph.nodeLinkTable.GetLinks()) { Assert.That(link.fromNode != add2); Assert.That(link.toNode != add2); } }
void CompareGraphs(PWGraph g1, PWGraph g2) { //Compare the two graphs node and link count: Assert.That(g1.nodes.Count == g2.nodes.Count, "Bad node count !"); Assert.That(g1.nodeLinkTable.GetLinks().Count() == g2.nodeLinkTable.GetLinks().Count(), "Bad links count !"); //Compare node count: Assert.That(g1.nodes.Count == g2.nodes.Count, "Bad node count !"); //Compare for node and links: for (int i = 0; i < g1.nodes.Count; i++) { var exNode = g1.nodes[i]; var newNode = g2.nodes[i]; Assert.That(exNode.GetType() == newNode.GetType(), "Node type differs: expected " + exNode.GetType() + ", got:" + newNode.GetType()); var exAnchorFields = exNode.anchorFields.ToList(); var newAnchorFields = newNode.anchorFields.ToList(); for (int j = 0; j < exAnchorFields.Count; j++) { var exAnchors = exAnchorFields[j].anchors; var newAnchors = newAnchorFields[j].anchors; for (int k = 0; k < exAnchors.Count; k++) { var exLinks = exAnchors[k].links.ToList(); var newLinks = newAnchors[k].links.ToList(); Assert.That(exLinks.Count == newLinks.Count, "Anchors " + exAnchors[k] + " and " + newAnchors[k] + " have different link count"); for (int l = 0; l < exLinks.Count; l++) { Assert.That(exLinks[l].fromNode.GetType() == newLinks[l].fromNode.GetType()); Assert.That(newLinks[l].toNode.GetType() == newLinks[l].toNode.GetType()); } } } } }
PWGraph DrawGraphInput(PWGraph graph) { currentGraph = graph; if (GUILayout.Button("Load graph")) { currentPickerWindow = EditorGUIUtility.GetControlID(FocusType.Passive) + 100; EditorGUIUtility.ShowObjectPicker <PWGraph>(graph, false, "", currentPickerWindow); } if (Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == currentPickerWindow) { UnityEngine.Object selected = null; selected = EditorGUIUtility.GetObjectPickerObject(); if (selected != null) { graph = (PWGraph)selected; } } return(graph); }
public PWGraphSettingsBar(PWGraph graph) { this.graph = graph; delayedChanges.BindCallback(graphProcessKey, (unused) => { graph.Process(); }); onDraw = DrawDefault; }
public PWGraphOptionBar(PWGraph graph) { this.graph = graph; }
public PWGraphTerrainManager(PWGraph graph) { this.graph = graph; }
void GraphChangedCallback(PWGraph newGraph) { if (newGraph == null) { return; } terrainManager = new PWGraphTerrainManager(graph); settingsBar.onDraw = (rect) => { settingsBar.DrawDefault(rect); EditorGUI.BeginChangeCheck(); if (PWGUI.BeginFade("Scaled preview", ref scaledPreviewFoldout, false)) { EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("Active", (mainGraph.scaledPreviewEnabled) ? PWStyles.pressedButton : PWStyles.button)) { mainGraph.scaledPreviewEnabled = !mainGraph.scaledPreviewEnabled; PWGUIManager.displaySamplerStepBounds = mainGraph.scaledPreviewEnabled; mainGraph.Process(); } } EditorGUILayout.EndHorizontal(); mainGraph.scaledPreviewRatio = EditorGUILayout.Slider("Ratio", mainGraph.scaledPreviewRatio, 1, 128); mainGraph.scaledPreviewChunkSize = EditorGUILayout.IntSlider("Chunk size", mainGraph.scaledPreviewChunkSize, 32, 2048); float scale = (mainGraph.scaledPreviewRatio * mainGraph.scaledPreviewChunkSize) / (mainGraph.nonModifiedChunkSize * mainGraph.nonModifiedStep); EditorGUILayout.LabelField("Scale: " + scale); } PWGUI.EndFade(); if (PWGUI.BeginFade("Renderer settings", ref terrainSettingsFoldout, false)) { terrainManager.DrawTerrainSettings(rect, mainGraph.materializerType); } PWGUI.EndFade(); /*if (PWGUI.BeginFade("Geological settings", ref geologicalSettingsFoldout, false)) * { * mainGraph.geologicTerrainStep = graph.PWGUI.Slider("Geological terrain step: ", mainGraph.geologicTerrainStep, 4, 64); * mainGraph.geologicDistanceCheck = graph.PWGUI.IntSlider("Geological search distance: ", mainGraph.geologicDistanceCheck, 1, 4); * } * PWGUI.EndFade();*/ if (PWGUI.BeginFade("Chunk settings")) { //seed GUI.SetNextControlName("seed"); mainGraph.seed = EditorGUILayout.IntField("Seed", mainGraph.seed); EditorGUI.BeginDisabledGroup(mainGraph.scaledPreviewEnabled); { //chunk size: GUI.SetNextControlName("chunk size"); mainGraph.chunkSize = EditorGUILayout.IntField("Chunk size", mainGraph.chunkSize); mainGraph.chunkSize = Mathf.Clamp(mainGraph.chunkSize, 1, 1024); //step: float min = 0.1f; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("step", PWStyles.prefixLabel); mainGraph.step = mainGraph.PWGUI.Slider(mainGraph.step, ref min, ref mainGraph.maxStep, 0.01f, false, true); EditorGUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); } PWGUI.EndFade(); if (EditorGUI.EndChangeCheck()) { delayedChanges.UpdateValue(graphProcessKey); } }; }
public PWGraphNodeSelectorBar(PWGraph graph) { this.graph = graph; OnNodeClicked = DefaultNodeClickAction; }