Exemplo n.º 1
0
        private void SaveNewNode(Node node)
        {
            if (mainNodeCanvas.livesInScene)
            {
                return;
            }
            if (!mainNodeCanvas.nodes.Contains(node))
            {
                return;
            }

            CheckCurrentCache();

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

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

            // Fetch the associated MainEditorState
            if (mainNodeCanvas.editorStates.Length > 0)
            {
                mainEditorState = mainNodeCanvas.editorStates.Length == 1? mainNodeCanvas.editorStates[0] : mainNodeCanvas.editorStates.First((NodeEditorState state) => state.name == "MainEditorState");
            }
            if (mainEditorState == null)
            {
                NewEditorState();
                NodeEditorSaveManager.AddSubAsset(mainEditorState, lastSessionPath);
            }

            CheckCurrentCache();

            NodeEditor.RecalculateAll(mainNodeCanvas);
            Repaint();
        }
Exemplo n.º 3
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();
                }
            }
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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();
        }
        public NPBehaveCanvasDataManager GetCurrentCanvasDatas()
        {
            if (this.npBehaveCanvasDataManager == null)
            {
                Object[] subAssets = AssetDatabase.LoadAllAssetRepresentationsAtPath(this.savePath);
                foreach (var subAsset in subAssets)
                {
                    if (subAsset is NPBehaveCanvasDataManager npBbDataManager)
                    {
                        return(npBbDataManager);
                    }
                }

                this.npBehaveCanvasDataManager = CreateInstance <NPBehaveCanvasDataManager>();
                //Log.Info("新建数据仓库");
                this.npBehaveCanvasDataManager.name = "当前Canvas数据库";
                NodeEditorSaveManager.AddSubAsset(this.npBehaveCanvasDataManager, this);
            }

            return(this.npBehaveCanvasDataManager);
        }
Exemplo n.º 7
0
        private void SaveNewNodeKnob(NodeKnob knob)
        {
            if (mainNodeCanvas.livesInScene)
            {
                return;
            }
            if (!mainNodeCanvas.nodes.Contains(knob.body))
            {
                return;
            }

            CheckCurrentCache();

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

            EditorUtility.SetDirty(mainNodeCanvas);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }