public void SideGUI()
    {
        GUILayout.BeginArea(new Rect(canvasRect.x + state.canvasRect.width, state.canvasRect.y, 200, state.canvasRect.height), NodeEditorGUI.nodeSkin.box);
        GUILayout.Label(new GUIContent("Node Editor (" + canvas.name + ")", "The currently opened canvas in the Node Editor"));
        screenSize = GUILayout.Toggle(screenSize, "Adapt to Screen");
        GUILayout.Label("FPS: " + FPSCounter.currentFPS);

        GUILayout.Label(new GUIContent("Node Editor (" + canvas.name + ")"), NodeEditorGUI.nodeLabelBold);

                #if UNITY_EDITOR
        if (GUILayout.Button(new GUIContent("Save Canvas", "Saves the Canvas to a Canvas Save File in the Assets Folder")))
        {
            string path = UnityEditor.EditorUtility.SaveFilePanelInProject("Save Node Canvas", "Node Canvas", "asset", "", NodeEditor.editorPath + "Resources/Saves/");
            if (!string.IsNullOrEmpty(path))
            {
                NodeEditorSaveManager.SaveNodeCanvas(path, true, canvas, state);
            }
        }

        if (GUILayout.Button(new GUIContent("Load Canvas", "Loads the Canvas from a Canvas Save File in the Assets Folder")))
        {
            string path = UnityEditor.EditorUtility.OpenFilePanel("Load Node Canvas", NodeEditor.editorPath + "Resources/Saves/", "asset");
            if (!path.Contains(Application.dataPath))
            {
                if (!string.IsNullOrEmpty(path))
                {
                    Debug.LogWarning("You should select an asset inside your project folder!");
                }
            }
            else
            {
                path = path.Replace(Application.dataPath, "Assets");
                LoadNodeCanvas(path);
            }
        }
                #endif

        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(canvas);
        }

        if (GUILayout.Button("Force Re-Init"))
        {
            NodeEditor.ReInit(true);
        }

        NodeEditorGUI.knobSize = RTEditorGUI.IntSlider(new GUIContent("Handle Size", "The size of the Node Input/Output handles"), NodeEditorGUI.knobSize, 12, 20);
        state.zoom             = RTEditorGUI.Slider(new GUIContent("Zoom", "Use the Mousewheel. Seriously."), state.zoom, 0.6f, 2);

        GUILayout.EndArea();
    }
Пример #2
0
        /// <summary>
        /// Creates a new cache save file for the currently loaded canvas
        /// Only called when a new canvas is created or loaded
        /// </summary>
        private void SaveCache()
        {
            if (mainNodeCanvas.livesInScene)
            {
                return;
            }

            mainNodeCanvas.editorStates = new NodeEditorState[] { mainEditorState };
            NodeEditorSaveManager.SaveNodeCanvas(lastSessionPath, mainNodeCanvas, false);

            CheckCurrentCache();
        }
Пример #3
0
        private void SaveCache()
        {
            //DeleteCache (); // Delete old cache
            string canvasName = mainNodeCanvas.name;

            EditorPrefs.SetString("NodeEditorLastSession", canvasName);
            NodeEditorSaveManager.SaveNodeCanvas(tempSessionPath + "/LastSession.asset", false, mainNodeCanvas, mainEditorState);
            mainNodeCanvas.name = canvasName;

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Пример #4
0
        public void SideGUI()
        {
            GUILayout.Label(new GUIContent("Node Editor (" + canvas.name + ")", "The currently opened canvas in the Node Editor"));
            screenSize = GUILayout.Toggle(screenSize, "Adapt to Screen");
            GUILayout.Label("FPS: " + FPSCounter.currentFPS);

            GUILayout.Label(new GUIContent("Node Editor (" + canvas.name + ")"), NodeEditorGUI.nodeLabelBold);

            if (GUILayout.Button(new GUIContent("New Canvas", "Loads an empty Canvas")))
            {
                NewNodeCanvas();
            }

            GUILayout.Space(6);

                #if UNITY_EDITOR
            if (GUILayout.Button(new GUIContent("Save Canvas", "Saves the Canvas to a Canvas Save File in the Assets Folder")))
            {
                string path = UnityEditor.EditorUtility.SaveFilePanelInProject("Save Node Canvas", "Node Canvas", "asset", "", NodeEditor.editorPath + "Resources/Saves/");
                if (!string.IsNullOrEmpty(path))
                {
                    NodeEditorSaveManager.SaveNodeCanvas(path, canvas, true);
                }
            }

            if (GUILayout.Button(new GUIContent("Load Canvas", "Loads the Canvas from a Canvas Save File in the Assets Folder")))
            {
                string path = UnityEditor.EditorUtility.OpenFilePanel("Load Node Canvas", NodeEditor.editorPath + "Resources/Saves/", "asset");
                if (!path.Contains(Application.dataPath))
                {
                    if (!string.IsNullOrEmpty(path))
                    {
                        Debug.LogWarning("You should select an asset inside your project folder!");
                    }
                }
                else
                {
                    path = path.Replace(Application.dataPath, "Assets");
                    LoadNodeCanvas(path);
                }
            }
            GUILayout.Space(6);
                #endif

            GUILayout.BeginHorizontal();
            sceneCanvasName = GUILayout.TextField(sceneCanvasName, GUILayout.ExpandWidth(true));
            if (GUILayout.Button(new GUIContent("Save to Scene", "Saves the Canvas to the Scene"), GUILayout.ExpandWidth(false)))
            {
                SaveSceneNodeCanvas(sceneCanvasName);
            }
            GUILayout.EndHorizontal();

            if (GUILayout.Button(new GUIContent("Load from Scene", "Loads the Canvas from the Scene")))
            {
                NodeEditorFramework.Utilities.GenericMenu menu = new NodeEditorFramework.Utilities.GenericMenu();
                foreach (string sceneSave in NodeEditorSaveManager.GetSceneSaves())
                {
                    menu.AddItem(new GUIContent(sceneSave), false, LoadSceneCanvasCallback, (object)sceneSave);
                }
                menu.Show(loadScenePos);
            }
            if (Event.current.type == EventType.Repaint)
            {
                Rect popupPos = GUILayoutUtility.GetLastRect();
                loadScenePos = new Vector2(popupPos.x + 2, popupPos.yMax + 2);
            }

            GUILayout.Space(6);

            if (GUILayout.Button(new GUIContent("Recalculate All", "Initiates complete recalculate. Usually does not need to be triggered manually.")))
            {
                NodeEditor.RecalculateAll(canvas);
            }

            if (GUILayout.Button("Force Re-Init"))
            {
                NodeEditor.ReInit(true);
            }

            NodeEditorGUI.knobSize = RTEditorGUI.IntSlider(new GUIContent("Handle Size", "The size of the Node Input/Output handles"), NodeEditorGUI.knobSize, 12, 20);
            state.zoom             = RTEditorGUI.Slider(new GUIContent("Zoom", "Use the Mousewheel. Seriously."), state.zoom, 0.6f, 2);
        }
Пример #5
0
 /// <summary>
 /// Saves the mainNodeCanvas and it's associated mainEditorState as an asset at path
 /// </summary>
 public void SaveNodeCanvas(string path)
 {
     mainNodeCanvas.editorStates = new NodeEditorState[] { mainEditorState };
     NodeEditorSaveManager.SaveNodeCanvas(path, mainNodeCanvas, true);
     Repaint();
 }
Пример #6
0
    protected internal override void NodeGUI()
    {
        GUILayout.BeginHorizontal();
#if UNITY_EDITOR
        if (GUILayout.Button(new GUIContent("Load", "Loads the group from an extern Canvas Asset File.")))
        {
            string path = UnityEditor.EditorUtility.OpenFilePanel("Load Node Canvas", NodeEditor.editorPath + "Saves/", "asset");
            if (!path.Contains(Application.dataPath))
            {
                // TODO: Generic Notification
                //if (path != String.Empty)
                //ShowNotification (new GUIContent ("You should select an asset inside your project folder!"));
                return;
            }
            path = path.Replace(Application.dataPath, "Assets");
            LoadNodeCanvas(path);
            //AdoptInputsOutputs ();
        }
        if (GUILayout.Button(new GUIContent("Save", "Saves the group as a new Canvas Asset File")))
        {
            NodeEditorSaveManager.SaveNodeCanvas(UnityEditor.EditorUtility.SaveFilePanelInProject("Save Group Node Canvas", "Group Canvas", "asset", "", NodeEditor.editorPath + "Saves/"), nodeGroupCanvas);
        }
#endif
        if (GUILayout.Button(new GUIContent("New Group Canvas", "Creates a new Canvas")))
        {
            nodeGroupCanvas = CreateInstance <NodeCanvas> ();

            editorState         = CreateInstance <NodeEditorState> ();
            editorState.drawing = edit;
            editorState.name    = "GroupNode_EditorState";

            Node node = NodeTypes.getDefaultNode("exampleNode");
            if (node != null)
            {
                NodeCanvas prevNodeCanvas = NodeEditor.curNodeCanvas;
                NodeEditor.curNodeCanvas = nodeGroupCanvas;
                node = node.Create(Vector2.zero);
                node.InitBase();
                NodeEditor.curNodeCanvas = prevNodeCanvas;
            }
        }
        GUILayout.EndHorizontal();

        if (nodeGroupCanvas != null)
        {
            foreach (NodeInput input in Inputs)
            {
                input.DisplayLayout();
            }

            foreach (NodeOutput output in Outputs)
            {
                output.DisplayLayout();
            }

            if (!edit)
            {
                if (GUILayout.Button("Edit Node Canvas"))
                {
                    rect = openedRect;
                    edit = true;
                    editorState.canvasRect = GUILayoutUtility.GetRect(canvasSize.x, canvasSize.y, GUIStyle.none);
                    editorState.drawing    = true;
                }
            }
            else
            {
                if (GUILayout.Button("Stop editing Node Canvas"))
                {
                    nodeRect.position = openedRect.position + new Vector2(canvasSize.x / 2 - nodeRect.width / 2, 0);
                    rect = nodeRect;
                    edit = false;
                    editorState.drawing = false;
                }

                Rect canvasRect = GUILayoutUtility.GetRect(canvasSize.x, canvasSize.y, new GUILayoutOption[] { GUILayout.ExpandWidth(false) });
                if (Event.current.type != EventType.Layout)
                {
                    editorState.canvasRect = canvasRect;
                    Rect canvasControlRect = editorState.canvasRect;
                    canvasControlRect.position += rect.position + contentOffset;
                    NodeEditor.curEditorState.ignoreInput.Add(NodeEditorFramework.NodeEditor.CanvasGUIToScreenRect(canvasControlRect));
                }

                NodeEditor.DrawSubCanvas(nodeGroupCanvas, editorState);


                GUILayout.BeginArea(new Rect(canvasSize.x + 8, 45, 200, canvasSize.y), GUI.skin.box);
                GUILayout.Label(new GUIContent("Node Editor (" + nodeGroupCanvas.name + ")", "The currently opened canvas in the Node Editor"));
                                #if UNITY_EDITOR
                editorState.zoom = UnityEditor.EditorGUILayout.Slider(new GUIContent("Zoom", "Use the Mousewheel. Seriously."), editorState.zoom, 0.6f, 2);
                                #endif
                GUILayout.EndArea();


                // Node is drawn by parent nodeCanvas, usually the mainNodeCanvas, because the zoom feature requires it to be drawn outside of any GUI group
            }
        }
    }
Пример #7
0
 /// <summary>
 /// Saves the mainNodeCanvas and it's associated mainEditorState as an asset at path
 /// </summary>
 public void SaveNodeCanvas(string path)
 {
     NodeEditorSaveManager.SaveNodeCanvas(path, true, mainNodeCanvas, mainEditorState);
     //SaveCache ();
     Repaint();
 }