예제 #1
0
        private void LoadCache()
        {
            string lastSessionName = EditorPrefs.GetString("NodeEditorLastSession");
            string path            = tempSessionPath + "/LastSession.asset";

            mainNodeCanvas = NodeEditorSaveManager.LoadNodeCanvas(path, false);
            if (mainNodeCanvas == null)
            {
                NewNodeCanvas();
            }
            else
            {
                mainNodeCanvas.name = lastSessionName;
                List <NodeEditorState> editorStates = NodeEditorSaveManager.LoadEditorStates(path, false);
                if (editorStates == null || editorStates.Count == 0 || (mainEditorState = editorStates.Find(x => x.name == "MainEditorState")) == null)
                {                 // New NodeEditorState
                    mainEditorState        = CreateInstance <NodeEditorState> ();
                    mainEditorState.canvas = mainNodeCanvas;
                    mainEditorState.name   = "MainEditorState";
                    NodeEditorSaveManager.AddSubAsset(mainEditorState, path);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Loads the canvas from the cache save file
        /// Called whenever a reload was made
        /// </summary>
        private void LoadCache()
        {
                        #if UNITY_EDITOR
            if (!useCache)
            {
                NewNodeCanvas();
                return;
            }
            // Try to load the NodeCanvas
            if (
                (!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);
                        #if EDITOR_CACHE_ASSET
            if (!nodeCanvas.livesInScene && !UnityEditor.AssetDatabase.Contains(editorState))
            {
                NodeEditorSaveManager.AddSubAsset(editorState, lastSessionPath);
            }
                        #endif


            CheckCurrentCache();
            UpdateCanvasInfo();
            nodeCanvas.TraverseAll();
            NodeEditor.RepaintClients();
                        #endif
        }
예제 #3
0
        private void SaveNewNode(Node node)
        {
            if (!useCache)
            {
                return;
            }
            CheckCurrentCache();

            if (nodeCanvas.livesInScene)
            {
                return;
            }
            if (!nodeCanvas.nodes.Contains(node))
            {
                return;
            }

            NodeEditorSaveManager.AddSubAsset(node, lastSessionPath);
            foreach (ScriptableObject so in node.GetScriptableObjects())
            {
                NodeEditorSaveManager.AddSubAsset(so, node);
            }

            foreach (NodeKnob knob in node.nodeKnobs)
            {
                NodeEditorSaveManager.AddSubAsset(knob, node);
                foreach (ScriptableObject so in knob.GetScriptableObjects())
                {
                    NodeEditorSaveManager.AddSubAsset(so, knob);
                }
            }

            UpdateCacheFile();
        }
예제 #4
0
        private void SaveNewNodeKnob(NodeKnob knob)
        {
            if (!useCache)
            {
                return;
            }
            CheckCurrentCache();

            if (nodeCanvas.livesInScene)
            {
                return;
            }
            if (!nodeCanvas.nodes.Contains(knob.body))
            {
                return;
            }

            NodeEditorSaveManager.AddSubAsset(knob, knob.body);
            foreach (ScriptableObject so in knob.GetScriptableObjects())
            {
                NodeEditorSaveManager.AddSubAsset(so, knob);
            }

            UpdateCacheFile();
        }
예제 #5
0
        private void SaveNewNode(Node node)
        {
            if (!mainNodeCanvas.nodes.Contains(node))
            {
                throw new UnityException("Cache system: Writing new Node to save file failed as Node is not part of the Cache!");
            }
            string path = tempSessionPath + "/LastSession.asset";

            if (AssetDatabase.GetAssetPath(mainNodeCanvas) != path)
            {
                throw new UnityException("Cache system error: Current Canvas is not saved as the temporary cache!");
            }
            NodeEditorSaveManager.AddSubAsset(node, path);
            for (int knobCnt = 0; knobCnt < node.nodeKnobs.Count; knobCnt++)
            {
                NodeEditorSaveManager.AddSubAsset(node.nodeKnobs [knobCnt], path);
            }
            for (int transCnt = 0; transCnt < node.transitions.Count; transCnt++)
            {
                if (node.transitions[transCnt].startNode == node)
                {
                    NodeEditorSaveManager.AddSubAsset(node.transitions [transCnt], path);
                }
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
        /// <summary>
        /// Loads the canvas from the cache save file
        /// Called whenever a reload was made
        /// </summary>
        private void LoadCache()
        {
            if (!useCache)
            {
                NewNodeCanvas();
                return;
            }
            // Try to load the NodeCanvas
            if (!File.Exists(lastSessionPath) || (nodeCanvas = NodeEditorSaveManager.LoadNodeCanvas(lastSessionPath, false)) == null)
            //if(true)
            {
                NewNodeCanvas();
                return;
            }

            // Fetch the associated MainEditorState
            editorState = NodeEditorSaveManager.ExtractEditorState(nodeCanvas, MainEditorStateIdentifier);
            if (!UnityEditor.AssetDatabase.Contains(editorState))
            {
                NodeEditorSaveManager.AddSubAsset(editorState, lastSessionPath);
            }

            CheckCurrentCache();

            NodeEditor.RecalculateAll(nodeCanvas);
            NodeEditor.RepaintClients();
        }
예제 #7
0
        public override ConnectionPort CreateNew(Node body)
        {
            ValueConnectionKnob knob = ScriptableObject.CreateInstance <ValueConnectionKnob>();

            knob.Init(body, Name, Direction, StyleID, NodeSide, NodeSidePos);
            knob.maxConnectionCount = MaxConnectionCount;
            NodeEditorSaveManager.AddSubAsset(knob, body);
            return(knob);
        }
예제 #8
0
        /// <summary>
        /// Creates a new EditorState for the current NodeCanvas
        /// </summary>
        public void NewEditorState()
        {
            editorState             = ScriptableObject.CreateInstance <NodeEditorState>();
            editorState.canvas      = nodeCanvas;
            editorState.name        = MainEditorStateIdentifier;
            nodeCanvas.editorStates = new NodeEditorState[] { editorState };

            UnityEditor.EditorUtility.SetDirty(nodeCanvas);
            NodeEditorSaveManager.AddSubAsset(editorState, nodeCanvas);
        }
예제 #9
0
        public virtual ConnectionPort CreateNew(Node body)
        {
            ConnectionPort port = ScriptableObject.CreateInstance <ConnectionPort>();

            port.Init(body, Name);
            port.direction          = Direction;
            port.styleID            = StyleID;
            port.maxConnectionCount = MaxConnectionCount;
            NodeEditorSaveManager.AddSubAsset(port, body);
            return(port);
        }
예제 #10
0
        private void SaveNewTransition(Transition transition)
        {
            if (!mainNodeCanvas.nodes.Contains(transition.startNode) || !mainNodeCanvas.nodes.Contains(transition.endNode))
            {
                throw new UnityException("Cache system: Writing new Transition to save file failed as Node members are not part of the Cache!");
            }
            string path = tempSessionPath + "/LastSession.asset";

            if (AssetDatabase.GetAssetPath(mainNodeCanvas) != path)
            {
                throw new UnityException("Cache system error: Current Canvas is not saved as the temporary cache!");
            }
            NodeEditorSaveManager.AddSubAsset(transition, path);

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
예제 #11
0
        private void SaveNewNode(Node node)
        {
            if (!mainNodeCanvas.nodes.Contains(node))
            {
                throw new UnityException("Cache system: Writing new Node to save file failed as Node is not part of the Cache!");
            }
            string path = tempSessionPath + "/LastSession.asset";

            if (AssetDatabase.GetAssetPath(mainNodeCanvas) != path)
            {
                throw new UnityException("Cache system error: Current Canvas is not saved as the temporary cache!");
            }
            NodeEditorSaveManager.AddSubAsset(node, path);
            foreach (NodeKnob knob in node.nodeKnobs)
            {
                NodeEditorSaveManager.AddSubAsset(knob, path);
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
예제 #12
0
        /// <summary>
        /// Creates a node of the specified ID at pos on the specified canvas, optionally auto-connecting the specified output to a matching input
        /// silent disables any events, init specifies whether OnCreate should be called
        /// </summary>
        public static Node Create(string nodeID, Vector2 pos, NodeCanvas hostCanvas,
                                  ConnectionPort connectingPort = null, bool silent = false, bool init = true)
        {
            if (string.IsNullOrEmpty(nodeID) || hostCanvas == null)
            {
                throw new ArgumentException();
            }
            if (!NodeCanvasManager.CheckCanvasCompability(nodeID, hostCanvas.GetType()))
            {
                throw new UnityException("Cannot create Node with ID '" + nodeID +
                                         "' as it is not compatible with the current canavs type (" +
                                         hostCanvas.GetType().ToString() + ")!");
            }
            if (!hostCanvas.CanAddNode(nodeID))
            {
                throw new UnityException("Cannot create Node with ID '" + nodeID + "' on the current canvas of type (" +
                                         hostCanvas.GetType().ToString() + ")!");
            }
            // Create node from data
            NodeTypeData data = NodeTypes.GetNodeData(nodeID);
            Node         node = (Node)CreateInstance(data.type);

            if (node == null)
            {
                return(null);
            }

            // Init node state
            node.canvas   = hostCanvas;
            node.name     = node.Title;
            node.autoSize = node.DefaultSize;
            node.position = pos;

            Undo.RecordObject(hostCanvas, "NodeEditor_新增保存");
            NodeEditorSaveManager.AddSubAsset(node, hostCanvas);
            ConnectionPortManager.UpdateConnectionPorts(node);
            if (init)
            {
                node.OnCreate();
            }

            if (connectingPort != null)
            {
                // Handle auto-connection and link the output to the first compatible input
                for (int i = 0; i < node.connectionPorts.Count; i++)
                {
                    if (node.connectionPorts[i].TryApplyConnection(connectingPort, silent))
                    {
                        break;
                    }
                }
            }

            // Add node to host canvas
            hostCanvas.nodes.Add(node);
            if (!silent)
            {
                // Callbacks
                NodeEditorCallbacks.IssueOnAddNode(node);
                hostCanvas.Validate();
                NodeEditor.RepaintClients();
            }

            return(node);
        }