private void DrawSideWindow() { GUILayout.Label(new GUIContent("Node Editor (" + mainNodeCanvas.name + ")", "Opened Canvas path: " + openedCanvasPath), NodeEditorGUI.nodeLabelBold); if (GUILayout.Button(new GUIContent("Save Canvas", "Saves the Canvas to a Canvas Save File in the Assets Folder"))) { string path = EditorUtility.SaveFilePanelInProject("Save Node Canvas", "Node Canvas", "asset", "", NodeEditor.editorPath + "Resources/Saves/"); if (!string.IsNullOrEmpty(path)) { SaveNodeCanvas(path); } } if (GUILayout.Button(new GUIContent("Load Canvas", "Loads the Canvas from a Canvas Save File in the Assets Folder"))) { string path = EditorUtility.OpenFilePanel("Load Node Canvas", NodeEditor.editorPath + "Resources/Saves/", "asset"); if (!path.Contains(Application.dataPath)) { if (!string.IsNullOrEmpty(path)) { ShowNotification(new GUIContent("You should select an asset inside your project folder!")); } } else { path = path.Replace(Application.dataPath, "Assets"); LoadNodeCanvas(path); } } if (GUILayout.Button(new GUIContent("New Canvas", "Loads an empty Canvas"))) { NewNodeCanvas(); } if (GUILayout.Button(new GUIContent("Recalculate All", "Initiates complete recalculate. Usually does not need to be triggered manually."))) { NodeEditor.RecalculateAll(mainNodeCanvas); } if (GUILayout.Button("Force Re-Init")) { NodeEditor.ReInit(true); } if (NodeEditor.isTransitioning(mainNodeCanvas) && GUILayout.Button("Stop Transitioning")) { NodeEditor.StopTransitioning(mainNodeCanvas); } NodeEditorGUI.knobSize = EditorGUILayout.IntSlider(new GUIContent("Handle Size", "The size of the Node Input/Output handles"), NodeEditorGUI.knobSize, 12, 20); mainEditorState.zoom = EditorGUILayout.Slider(new GUIContent("Zoom", "Use the Mousewheel. Seriously."), mainEditorState.zoom, 0.6f, 2); if (mainEditorState.selectedNode != null && Event.current.type != EventType.Ignore) { mainEditorState.selectedNode.DrawNodePropertyEditor(); } }
/// <summary> /// Creates and opens a new empty node canvas /// </summary> public void NewNodeCanvas() { // Else it will be stuck forever NodeEditor.StopTransitioning(mainNodeCanvas); // New NodeCanvas mainNodeCanvas = CreateInstance <NodeCanvas> (); mainNodeCanvas.name = "New Canvas"; // New NodeEditorState mainEditorState = CreateInstance <NodeEditorState> (); mainEditorState.canvas = mainNodeCanvas; mainEditorState.name = "MainEditorState"; openedCanvasPath = ""; SaveCache(); }
/// <summary> /// Loads the mainNodeCanvas and it's associated mainEditorState from an asset at path /// </summary> public void LoadNodeCanvas(string path) { // Else it will be stuck forever NodeEditor.StopTransitioning(mainNodeCanvas); // Load the NodeCanvas mainNodeCanvas = NodeEditorSaveManager.LoadNodeCanvas(path, true); if (mainNodeCanvas == null) { Debug.Log("Error loading NodeCanvas from '" + path + "'!"); NewNodeCanvas(); return; } // Load the associated MainEditorState List <NodeEditorState> editorStates = NodeEditorSaveManager.LoadEditorStates(path, true); if (editorStates.Count == 0) { mainEditorState = ScriptableObject.CreateInstance <NodeEditorState> (); Debug.LogError("The save file '" + path + "' did not contain an associated NodeEditorState!"); } else { mainEditorState = editorStates.Find(x => x.name == "MainEditorState"); if (mainEditorState == null) { mainEditorState = editorStates[0]; } } mainEditorState.canvas = mainNodeCanvas; openedCanvasPath = path; NodeEditor.RecalculateAll(mainNodeCanvas); SaveCache(); Repaint(); }