private static void HandleWindowPanning(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (state.panWindow)
            {             // Calculate change in panOffset
                Vector2 panOffsetChange = state.dragOffset;
                state.dragOffset = inputInfo.inputPos - state.dragStart;
                panOffsetChange  = (state.dragOffset - panOffsetChange) * state.zoom;
                // Apply panOffsetChange to panOffset
                state.panOffset += panOffsetChange;
                NodeEditor.RepaintClients();
            }
        }
        private static void CreateNodeCallback(object infoObj)
        {
            NodeEditorInputInfo callback = infoObj as NodeEditorInputInfo;

            if (callback == null)
            {
                throw new UnityException("Callback Object passed by context is not of type NodeEditorInputInfo!");
            }

            callback.SetAsCurrentEnvironment();
            Node.Create(callback.message, NodeEditor.ScreenToCanvasSpace(callback.inputPos), callback.editorState.connectOutput);
            callback.editorState.connectOutput = null;
            NodeEditor.RepaintClients();
        }
Exemple #3
0
        private static void HandleDraggingEnd(NodeEditorInputInfo inputInfo)
        {
            if (inputInfo.editorState.dragUserID == "group")
            {
                //				if (inputInfo.editorState.activeGroup != null )
                //					inputInfo.editorState.activeGroup.UpdatePins ();
                inputInfo.editorState.EndDrag("group");
                NodeEditor.RepaintClients();
            }

            UpdateGroupOrder();
            inputInfo.editorState.activeGroup = null;
            inputInfo.editorState.resizeGroup = false;
        }
Exemple #4
0
        [EventHandlerAttribute(EventType.MouseDown, -2)]          // Absolute second to call!
        private static void HandleSelecting(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (inputInfo.inputEvent.button == 0) //&& state.focusedNode != state.selectedNode)
            {                                     // Select focussed Node
                unfocusControlsForState = state;
                state.selectedNode      = state.focusedNode;
                if (inputInfo.inputEvent.shift)
                {
                    if (!state.selectedNodes.Contains(state.selectedNode))
                    {
                        state.selectedNodes.Add(state.selectedNode);
                    }
                }
                else
                if (inputInfo.inputEvent.control)
                {
                    if (state.selectedNodes.Contains(state.selectedNode))
                    {
                        state.selectedNodes.Remove(state.selectedNode);
                    }
                    if (state.selectedNodes.Count > 0)
                    {
                        state.selectedNode = state.selectedNodes[0];
                    }
                    else
                    {
                        state.selectedNode = null;
                    }
                }
                else
                {
                    if (!state.selectedNodes.Contains(state.selectedNode))
                    {
                        state.selectedNodes.Clear();
                    }
                }

                //                Debug.Log("Set Selected node "+ state.selectedNode);
                NodeEditor.RepaintClients();
                        #if UNITY_EDITOR
                if (state.selectedNode != null)
                {
                    UnityEditor.Selection.activeObject = state.selectedNode;
                }
                        #endif
            }
        }
Exemple #5
0
        /// <summary>
        /// Resizes the node to either the MinSize or to fit size of the GUILayout in NodeGUI
        /// </summary>
        protected internal virtual void AutoLayoutNode()
        {
            if (!AutoLayout || Event.current.type != EventType.Repaint)
            {
                return;
            }

            Vector2 size = new Vector2();

            size.y = Math.Max(nodeGUIHeight.y, MinSize.y);
            size.x = Math.Max(nodeGUIHeight.x, this.DefaultSize.x);

            autoSize = size;
            NodeEditor.RepaintClients();
        }
Exemple #6
0
        /// <summary>
        /// Init the Node Base after the Node has been created. This includes adding to canvas, and to calculate for the first time
        /// </summary>
        protected virtual void InitBase()
        {
            NodeEditor.RecalculateFrom(this);
            if (!NodeEditor.curNodeCanvas.nodes.Contains(this))
            {
                NodeEditor.curNodeCanvas.nodes.Add(this);
            }
#if UNITY_EDITOR
            if (String.IsNullOrEmpty(name))
            {
                name = UnityEditor.ObjectNames.NicifyVariableName(GetID);
            }
#endif
            NodeEditor.RepaintClients();
        }
Exemple #7
0
 /// <summary>
 /// Init the Node Base after the Node has been created. This includes adding to canvas, and to calculate for the first time
 /// </summary>
 protected internal void InitBase()
 {
     if (!NodeEditor.curNodeCanvas.nodes.Contains(this))
     {
         NodeEditor.curNodeCanvas.nodes.Add(this);
     }
     NodeEditor.curNodeCanvas.OnNodeChange(this);
                 #if UNITY_EDITOR
     if (String.IsNullOrEmpty(name))
     {
         name = UnityEditor.ObjectNames.NicifyVariableName(GetID);
     }
                 #endif
     NodeEditor.RepaintClients();
 }
        /// <summary>
        /// Saves the mainNodeCanvas and it's associated mainEditorState as an asset at path
        /// </summary>
        public void SaveNodeCanvas(string path)
        {
            nodeCanvas.editorStates = new NodeEditorState[] { editorState };
            bool switchedToFile = nodeCanvas.livesInScene;

            NodeEditorSaveManager.SaveNodeCanvas(path, ref nodeCanvas, true);
            if (switchedToFile)
            {
                RecreateCache();
            }
            else
            {
                SaveCache(false);
            }
            NodeEditor.RepaintClients();
        }
Exemple #9
0
        /// <summary>
        /// Loads the mainNodeCanvas and it's associated mainEditorState from an asset at path
        /// </summary>
        public void LoadNodeCanvas(string path)
        {
            // Try to load the NodeCanvas
            if (!File.Exists(path) || (nodeCanvas = NodeEditorSaveManager.LoadNodeCanvas(path, true)) == null)
            {
                NewNodeCanvas();
                return;
            }
            editorState = NodeEditorSaveManager.ExtractEditorState(nodeCanvas, MainEditorStateIdentifier);

            openedCanvasPath = path;
            RecreateCache();
            UpdateCanvasInfo();
            nodeCanvas.TraverseAll();
            NodeEditor.RepaintClients();
        }
Exemple #10
0
        private static void HandleNodeSnap(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (state.selectedNode != null)
            {             // Snap selected Node's position and the drag to multiples of 10
                state.selectedNode.position.x = Mathf.Round(state.selectedNode.rect.x / 10) * 10;
                state.selectedNode.position.y = Mathf.Round(state.selectedNode.rect.y / 10) * 10;
            }
            if (state.activeGroup != null)
            {
                state.activeGroup.rect.x = Mathf.Round(state.activeGroup.rect.x / 10) * 10;
                state.activeGroup.rect.y = Mathf.Round(state.activeGroup.rect.y / 10) * 10;
            }
            NodeEditor.RepaintClients();
        }
Exemple #11
0
 /// <summary>
 /// Sets the current canvas, handling all cache operations
 /// </summary>
 public void SetCanvas(NodeCanvas canvas)
 {
     if (canvas == null)
     {
         NewNodeCanvas();
     }
     else if (nodeCanvas != canvas)
     {
         canvas.Validate();
         nodeCanvas  = canvas;
         editorState = NodeEditorSaveManager.ExtractEditorState(nodeCanvas, MainEditorStateIdentifier);
         RecreateCache();
         UpdateCanvasInfo();
         nodeCanvas.TraverseAll();
         NodeEditor.RepaintClients();
     }
 }
        [EventHandlerAttribute(EventType.MouseDown, -2)]          // Absolute second to call!
        private static void HandleSelecting(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (inputInfo.inputEvent.button == 0 && state.focusedNode != state.selectedNode)
            {             // Select focussed Node
                unfocusControlsForState = state;
                state.selectedNode      = state.focusedNode;
                NodeEditor.RepaintClients();
                        #if UNITY_EDITOR
                if (state.selectedNode != null)
                {
                    UnityEditor.Selection.activeObject = state.selectedNode;
                }
                        #endif
            }
        }
Exemple #13
0
        private static void HandleWindowPanning(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (state.panWindow)
            {             // Calculate change in panOffset
                if (inputInfo.editorState.dragUserID == "window")
                {
                    state.panOffset += state.UpdateDrag("window", inputInfo.inputPos);
                }
                else
                {
                    state.panWindow = false;
                }
                NodeEditor.RepaintClients();
            }
        }
        /// <summary>
        /// Loads the mainNodeCanvas and it's associated mainEditorState from an asset at path
        /// </summary>
        public void LoadNodeCanvas(string path)
        {
            // Try to load the NodeCanvas
            if (!File.Exists(path) || (nodeCanvas = NodeEditorSaveManager.LoadNodeCanvas(path, true)) == null)
            {
                NewNodeCanvas();
                return;
            }
            editorState = NodeEditorSaveManager.ExtractEditorState(nodeCanvas, MainEditorStateIdentifier);

            openedCanvasPath = path;
            if (useCache)
            {
                SaveCache();
            }
            NodeEditor.RecalculateAll(nodeCanvas);
            NodeEditor.RepaintClients();
        }
Exemple #15
0
        private static void HandleNodeDragging(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (state.dragNode)
            {             // If conditions apply, drag the selected node, else disable dragging
                if (state.selectedNode != null && inputInfo.editorState.dragUserID == "node")
                {         // Apply new position for the dragged node
                    state.UpdateDrag("node", inputInfo.inputPos);
                    state.selectedNode.position = state.dragObjectPos;
                    NodeEditor.RepaintClients();
                }
                else
                {
                    state.dragNode = false;
                }
            }
        }
        /// <summary>
        /// Loads the canvas from the cache save file
        /// Called whenever a reload was made
        /// </summary>
        public void LoadCache()
        {
#if CACHE
            if (!useCache)
            {             // Simply create a ne canvas
                NewNodeCanvas();
                return;
            }

            bool skipLoad = false;
            if (cacheMemorySODump)
            {             // Check if a memory dump has been found, if so, load that
                nodeCanvas = ResourceManager.LoadResource <NodeCanvas>(SOMemoryDumpPath);
                if (nodeCanvas != null && !nodeCanvas.Validate(false))
                {
                    Debug.LogWarning("Cache Dump corrupted! Loading crash-proof lastSession, you might have lost a bit of work. \n "
                                     + "To prevent this from happening in the future, allow the Node Editor to properly save the cache "
                                     + "by clicking out of the window before switching scenes, since there are no callbacks to facilitate this!");
                    nodeCanvas = null;
                    UnityEditor.AssetDatabase.DeleteAsset(SOMemoryDumpPath);
                }
                if (nodeCanvas != null)
                {
                    skipLoad = true;
                }
            }

            // Try to load the NodeCanvas
            if (!skipLoad &&
                (!File.Exists(lastSessionPath) || (nodeCanvas = NodeEditorSaveManager.LoadNodeCanvas(lastSessionPath, cacheWorkingCopy)) == null) &&                    // Check for asset cache
                (nodeCanvas = NodeEditorSaveManager.LoadSceneNodeCanvas("lastSession", cacheWorkingCopy)) == null)                                                      // Check for scene cache
            {
                NewNodeCanvas();
                return;
            }

            // Fetch the associated MainEditorState
            editorState = NodeEditorSaveManager.ExtractEditorState(nodeCanvas, MainEditorStateIdentifier);
            UpdateCanvasInfo();
            nodeCanvas.Validate();
            nodeCanvas.TraverseAll();
            NodeEditor.RepaintClients();
#endif
        }
        private static void HandleNodeDragging(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState editorState = inputInfo.editorState;

            if (editorState.dragNode)
            {
                if ((UnityEngine.Object)editorState.selectedNode != (UnityEngine.Object)null && GUIUtility.hotControl == 0)
                {
                    editorState.dragOffset = inputInfo.inputPos - editorState.dragStart;
                    editorState.selectedNode.rect.position = editorState.dragPos + editorState.dragOffset * editorState.zoom;
                    NodeEditorCallbacks.IssueOnMoveNode(editorState.selectedNode);
                    NodeEditor.RepaintClients();
                }
                else
                {
                    editorState.dragNode = false;
                }
            }
        }
Exemple #18
0
        private static void HandleNodeDragging(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (state.dragNode)
            {             // If conditions apply, drag the selected node, else disable dragging
                if (state.selectedNode != null && GUIUtility.hotControl == 0)
                {         // Calculate new position for the dragged object
                    state.dragOffset = inputInfo.inputPos - state.dragStart;
                    state.selectedNode.rect.position = state.dragPos + state.dragOffset * state.zoom;
                    NodeEditorCallbacks.IssueOnMoveNode(state.selectedNode);
                    NodeEditor.RepaintClients();
                }
                else
                {
                    state.dragNode = false;
                }
            }
        }
Exemple #19
0
 private static void HandleNodeSnap(NodeEditorInputInfo inputInfo)
 {
     if (inputInfo.inputEvent.modifiers == EventModifiers.Control || inputInfo.inputEvent.keyCode == KeyCode.LeftControl)
     {
         NodeEditorState state = inputInfo.editorState;
         if (state.selectedNode != null)
         {                 // Snap selected Node's position to multiples of 10
             state.selectedNode.position.x = Mathf.Round(state.selectedNode.rect.x / 10) * 10;
             state.selectedNode.position.y = Mathf.Round(state.selectedNode.rect.y / 10) * 10;
             NodeEditor.RepaintClients();
         }
         if (state.activeGroup != null)
         {                 // Snap active Group's position to multiples of 10
             state.activeGroup.rect.x = Mathf.Round(state.activeGroup.rect.x / 10) * 10;
             state.activeGroup.rect.y = Mathf.Round(state.activeGroup.rect.y / 10) * 10;
             NodeEditor.RepaintClients();
         }
     }
 }
Exemple #20
0
        /// <summary>
        /// Resizes the node to either the MinSize or to fit size of the GUILayout in #NodeGUI()
        /// </summary>
        protected internal virtual void ResizeNode()
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            if (!Resizable)
            {
                return;
            }

            Rect nodeRect = rect;

            Vector2 maxSize = new Vector2();

            maxSize.y = Math.Max(resizeToPosition.y, MinSize.y);

            List <NodeKnob> topBottomKnobs = nodeKnobs.Where(x => x.side == NodeSide.Bottom || x.side == NodeSide.Top).ToList();

            if (topBottomKnobs.Any())
            {
                float knobSize = topBottomKnobs.Max(x => x.GetGUIKnob().xMax - nodeRect.xMin);
                float minWidth = MinSize.x;

                maxSize.x = Math.Max(knobSize, minWidth);
            }
            else
            {
                maxSize.x = MinSize.x;
            }

            if (maxSize != nodeRect.size)
            {
                nodeRect.size = maxSize;
            }

            if (rect.size != nodeRect.size)
            {
                rect = nodeRect;
                NodeEditor.RepaintClients();
            }
        }
        private static void KB_MoveNode(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (state.selectedNode != null)
            {
                Vector2 pos = state.selectedNode.rect.position;

                int shiftAmount = 0;

                // Increase the distance moved to 10 if shift is being held.
                if (inputInfo.inputEvent.shift)
                {
                    shiftAmount = 10;
                }
                else
                {
                    shiftAmount = 5;
                }

                if (inputInfo.inputEvent.keyCode == KeyCode.RightArrow)
                {
                    pos = new Vector2(pos.x + shiftAmount, pos.y);
                }
                else if (inputInfo.inputEvent.keyCode == KeyCode.LeftArrow)
                {
                    pos = new Vector2(pos.x - shiftAmount, pos.y);
                }
                else if (inputInfo.inputEvent.keyCode == KeyCode.DownArrow)
                {
                    pos = new Vector2(pos.x, pos.y + shiftAmount);
                }
                else if (inputInfo.inputEvent.keyCode == KeyCode.UpArrow)
                {
                    pos = new Vector2(pos.x, pos.y - shiftAmount);
                }

                state.selectedNode.rect.position = pos;
                inputInfo.inputEvent.Use();
            }
            NodeEditor.RepaintClients();
        }
        /// <summary>
        /// Loads the mainNodeCanvas and it's associated mainEditorState from an asset at path
        /// </summary>
        public void LoadSceneNodeCanvas(string path)
        {
                #if UNITY_EDITOR
            if (useCache)
            {
                DeleteCache();
            }
                #endif
            // Try to load the NodeCanvas
            if ((nodeCanvas = NodeEditorSaveManager.LoadSceneNodeCanvas(path, true)) == null)
            {
                NewNodeCanvas();
                return;
            }
            editorState = NodeEditorSaveManager.ExtractEditorState(nodeCanvas, MainEditorStateIdentifier);

            openedCanvasPath = path;
            NodeEditor.RecalculateAll(nodeCanvas);
            NodeEditor.RepaintClients();
        }
        private static void HandleNodeDragging(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (state.dragNode)
            {             // If conditions apply, drag the selected node, else disable dragging
                if (state.selectedNode != null && GUIUtility.hotControl == 0)
                {         // Calculate new position for the dragged object
                    state.dragOffset = inputInfo.inputPos - state.dragStart;
                    Vector2 delta = (state.dragPos + state.dragOffset * state.zoom) - state.selectedNode.rect.position;
                    if (delta.magnitude > 1.0f)
                    {
                        state.didDragNode = true;
                    }
                    if (state.selectedNode != null && !state.selectedNodes.Contains(state.selectedNode))
                    {
                        state.selectedNode.rect.position = state.dragPos + state.dragOffset * state.zoom;
                    }
                    Vector2 deltaAll = (state.dragOffset * state.zoom);
                    foreach (var n in state.selectedNodes)
                    {
                        n.rect.position += delta;
                    }

                    if (inputInfo.inputEvent.alt)
                    {
                        Dictionary <Node, int> d = new Dictionary <Node, int>();
                        d[state.selectedNode] = 1;

                        MoveChildren(ref d, state.selectedNode, delta);
                    }
                    NodeEditorCallbacks.IssueOnMoveNode(state.selectedNode);
                    NodeEditor.RepaintClients();
                }
                else
                {
                    state.dragNode = false;
                }
            }
        }
Exemple #24
0
        /// <summary>
        /// Loads the mainNodeCanvas and it's associated mainEditorState from an asset at path
        /// </summary>
        public void LoadSceneNodeCanvas(string path)
        {
            if (path.StartsWith("SCENE/"))
            {
                path = path.Substring(6);
            }

            // Try to load the NodeCanvas
            if ((nodeCanvas = NodeEditorSaveManager.LoadSceneNodeCanvas(path, true)) == null)
            {
                NewNodeCanvas();
                return;
            }
            editorState = NodeEditorSaveManager.ExtractEditorState(nodeCanvas, MainEditorStateIdentifier);

            openedCanvasPath = path;
            nodeCanvas.Validate();
            RecreateCache();
            UpdateCanvasInfo();
            nodeCanvas.TraverseAll();
            NodeEditor.RepaintClients();
        }
        /// <summary>
        /// Loads the mainNodeCanvas and it's associated mainEditorState from an asset at path
        /// </summary>
        public void LoadNodeCanvas(string path)
        {
            // Try to load the NodeCanvas
            if (!File.Exists(path) || (nodeCanvas = NodeEditorSaveManager.LoadNodeCanvas(path, true)) == null)
            {
                NewNodeCanvas();
                return;
            }
            editorState = NodeEditorSaveManager.ExtractEditorState(nodeCanvas, MainEditorStateIdentifier);

            openedCanvasPath = path;
            nodeCanvas.Validate();
            RecreateCache();
            UpdateCanvasInfo();
            nodeCanvas.TraverseAll();
            NodeEditor.RepaintClients();

#if UNITY_EDITOR
            UnityEditor.AssetDatabase.DeleteAsset(SOMemoryDumpPath);
            NodeEditorUndoActions.CompleteSOMemoryDump(nodeCanvas);
#endif
        }
Exemple #26
0
        private static void KB_MoveNode(NodeEditorInputInfo inputInfo)
        {
            if (GUIUtility.keyboardControl > 0)
            {
                return;
            }
            NodeEditorState state = inputInfo.editorState;

            if (state.selectedNode != null)
            {
                Vector2 pos         = state.selectedNode.rect.position;
                int     shiftAmount = inputInfo.inputEvent.shift? 50 : 10;

                if (inputInfo.inputEvent.keyCode == KeyCode.RightArrow ||
                    inputInfo.inputEvent.keyCode == KeyCode.D)
                {
                    pos = new Vector2(pos.x + shiftAmount, pos.y);
                }
                else if (inputInfo.inputEvent.keyCode == KeyCode.LeftArrow ||
                         inputInfo.inputEvent.keyCode == KeyCode.A)
                {
                    pos = new Vector2(pos.x - shiftAmount, pos.y);
                }
                else if (inputInfo.inputEvent.keyCode == KeyCode.DownArrow ||
                         inputInfo.inputEvent.keyCode == KeyCode.S)
                {
                    pos = new Vector2(pos.x, pos.y + shiftAmount);
                }
                else if (inputInfo.inputEvent.keyCode == KeyCode.UpArrow ||
                         inputInfo.inputEvent.keyCode == KeyCode.W)
                {
                    pos = new Vector2(pos.x, pos.y - shiftAmount);
                }

                state.selectedNode.position = pos;
                inputInfo.inputEvent.Use();
            }
            NodeEditor.RepaintClients();
        }
Exemple #27
0
        /// <summary>
        /// Resizes the node to either the MinSize or to fit size of the GUILayout in NodeGUI
        /// </summary>
        protected internal virtual void AutoLayoutNode()
        {
            if (!AutoLayout || Event.current.type != EventType.Repaint)
            {
                return;
            }

            Rect    nodeRect = rect;
            Vector2 size     = new Vector2();

            size.y = Math.Max(nodeGUIHeight.y, MinSize.y) + 4;

            // TODO: Figure out this thing
            // Account for potential knobs that might occupy horizontal space
            //float knobSize = 0;
            //List<ConnectionKnob> verticalKnobs = connectionKnobs.Where (x => x.side == NodeSide.Bottom || x.side == NodeSide.Top).ToList ();
            //if (verticalKnobs.Count > 0)
            //	knobSize = verticalKnobs.Max ((ConnectionKnob knob) => knob.GetGUIKnob ().xMax - nodeRect.xMin);
            size.x = Math.Max(0, MinSize.x);

            autoSize = size;
            NodeEditor.RepaintClients();
        }
Exemple #28
0
        private static void HandleNodeDragging(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (state.dragNode)
            {
                // If conditions apply, drag the selected node, else disable dragging
                if (state.selectedNodes.Count > 0 && inputInfo.editorState.dragUserID == "node")
                {
                    // Apply new position for the dragged node
                    Vector2 newOffset = state.UpdateDrag("node", inputInfo.inputPos);
                    foreach (var node in state.selectedNodes)
                    {
                        node.position += newOffset;
                    }

                    NodeEditor.RepaintClients();
                }
                else
                {
                    state.dragNode = false;
                }
            }
        }
        /// <summary>
        /// Loads the canvas from the cache save file
        /// Called whenever a reload was made
        /// </summary>
        public void LoadCache()
        {
#if CACHE
            if (!useCache)
            {             // Simply create a ne canvas
                NewNodeCanvas();
                return;
            }

            bool skipLoad = false;
            if (cacheMemorySODump)
            {             // Check if a memory dump has been found, if so, load that
                nodeCanvas = ResourceManager.LoadResource <NodeCanvas>(SOMemoryDumpPath);
                if (nodeCanvas != null)
                {
                    skipLoad = true;
                }
            }

            // Try to load the NodeCanvas
            if (!skipLoad &&
                (!File.Exists(lastSessionPath) || (nodeCanvas = NodeEditorSaveManager.LoadNodeCanvas(lastSessionPath, cacheWorkingCopy)) == null) &&                    // Check for asset cache
                (nodeCanvas = NodeEditorSaveManager.LoadSceneNodeCanvas("lastSession", cacheWorkingCopy)) == null)                                                      // Check for scene cache
            {
                NewNodeCanvas();
                return;
            }

            // Fetch the associated MainEditorState
            editorState = NodeEditorSaveManager.ExtractEditorState(nodeCanvas, MainEditorStateIdentifier);
            UpdateCanvasInfo();
            nodeCanvas.Validate();
            nodeCanvas.TraverseAll();
            NodeEditor.RepaintClients();
#endif
        }
Exemple #30
0
        /// <summary>
        /// Loads the mainNodeCanvas and it's associated mainEditorState from an asset at path
        /// 加载一个Canvas
        /// </summary>
        public void LoadNodeCanvas(string path)
        {
            //如果路径一致,说明是同一个canvas
            if (NodeEditor.curEditorState != null && NodeEditor.curEditorState.canvas != null && (NodeEditor.curEditorState.canvas.savePath == path ||
                                                                                                  path.Contains(NodeEditor.curEditorState.canvas.savePath)) && (
                    NodeEditorSaveManager.GetLastCanvasPath() == path || path.Contains(NodeEditorSaveManager.GetLastCanvasPath())))
            {
                this.nodeCanvas = NodeEditor.curEditorState.canvas;
                return;
            }

            //如果不存在路径,则新建一个DefaultCanvas
            if (!File.Exists(path) || (nodeCanvas = NodeEditorSaveManager.LoadNodeCanvas(path)) == null)
            {
                NewNodeCanvas();
                return;
            }

            editorState = NodeEditorSaveManager.ExtractEditorState(nodeCanvas, MainEditorStateIdentifier);
            nodeCanvas.Validate();
            UpdateCanvasInfo();
            NodeEditor.RepaintClients();
            Debug.Log($"加载{path}成功");
        }