コード例 #1
0
        /// <summary>
        /// Saves the the given NodeCanvas along with the given NodeEditorStates if specified as a new asset, optionally as working copies
        /// </summary>
        public static void SaveNodeCanvas(string path, NodeCanvas nodeCanvas, bool createWorkingCopy)
        {
                #if !UNITY_EDITOR
            throw new System.NotImplementedException();
                #else
            if (string.IsNullOrEmpty(path))
            {
                throw new UnityException("Cannot save NodeCanvas: No spath specified to save the NodeCanvas " + (nodeCanvas != null? nodeCanvas.name : "") + " to!");
            }
            if (nodeCanvas == null)
            {
                throw new UnityException("Cannot save NodeCanvas: The specified NodeCanvas that should be saved to path " + path + " is null!");
            }
            if (nodeCanvas.livesInScene)
            {
                Debug.LogWarning("Attempting to save scene canvas " + nodeCanvas.name + " to an asset, scene object references will be broken!" + (!createWorkingCopy? " No workingCopy is going to be created, so your scene save is broken, too!" : ""));
            }
                #if UNITY_EDITOR
            if (!createWorkingCopy && UnityEditor.AssetDatabase.Contains(nodeCanvas) && UnityEditor.AssetDatabase.GetAssetPath(nodeCanvas) != path)
            {
                Debug.LogError("Trying to create a duplicate save file for '" + nodeCanvas.name + "'! Forcing to create a working copy!"); createWorkingCopy = true;
            }
                #endif

                #if UNITY_EDITOR
            nodeCanvas.BeforeSavingCanvas();

            // Preprocess the canvas
            ProcessCanvas(ref nodeCanvas, createWorkingCopy);
            nodeCanvas.livesInScene = false;

            // Write canvas and editorStates
            UnityEditor.AssetDatabase.CreateAsset(nodeCanvas, path);
            AddSubAssets(nodeCanvas.editorStates, nodeCanvas);

            // Write nodes + contents
            foreach (Node node in nodeCanvas.nodes)
            {             // Write node and additional scriptable objects
                AddSubAsset(node, nodeCanvas);
                AddSubAssets(node.GetScriptableObjects(), node);
                foreach (NodeKnob knob in node.nodeKnobs)
                {                 // Write knobs and their additional scriptable objects
                    AddSubAsset(knob, node);
                    AddSubAssets(knob.GetScriptableObjects(), knob);
                }
            }

            UnityEditor.AssetDatabase.SaveAssets();
            UnityEditor.AssetDatabase.Refresh();
                #else
            // TODO: Node Editor: Need to implement ingame-saving (Resources, AsssetBundles, ... won't work)
                #endif

            NodeEditorCallbacks.IssueOnSaveCanvas(nodeCanvas);
                #endif
        }
コード例 #2
0
        /// <summary>
        /// Saves the nodeCanvas in the current scene under the specified name along with the specified editorStates or, if specified, their working copies
        /// If also stored as an asset, it will loose the reference to the asset first
        /// </summary>
        public static void SaveSceneNodeCanvas(string saveName, ref NodeCanvas nodeCanvas, bool createWorkingCopy)
        {
            if (string.IsNullOrEmpty(saveName))
            {
                Debug.LogError("Cannot save Canvas to scene: No save name specified!");
                return;
            }

            if (!nodeCanvas.livesInScene
                #if UNITY_EDITOR // Make sure the canvas has no reference to an asset
                || UnityEditor.AssetDatabase.Contains(nodeCanvas)
                #endif
                )
            {
                //Debug.LogWarning ("Forced to create working copy of '" + saveName + "' when saving to scene because it already exists as an asset!");
                nodeCanvas = CreateWorkingCopy(nodeCanvas, true);
            }
            else
            {
                nodeCanvas.Validate();
            }

            nodeCanvas.livesInScene = true;
            nodeCanvas.name         = saveName;

                #if UNITY_EDITOR
            nodeCanvas.BeforeSavingCanvas();
                #endif

            NodeCanvas savedCanvas = nodeCanvas;
            // Preprocess canvas
            ProcessCanvas(ref savedCanvas, createWorkingCopy);

            // Get the saveHolder and store the canvas
            NodeCanvasSceneSave sceneSave = FindSceneSave(saveName);
            if (sceneSave == null)
            {
                sceneSave = sceneSaveHolder.AddComponent <NodeCanvasSceneSave> ();
            }
            sceneSave.savedNodeCanvas = savedCanvas;

                #if UNITY_EDITOR
            UnityEditor.EditorUtility.SetDirty(sceneSaveHolder);
                #endif
        }
コード例 #3
0
        /// <summary>
        /// Saves the nodeCanvas in the current scene under the specified name along with the specified editorStates or, if specified, their working copies
        /// If also stored as an asset, it will loose the reference to the asset first
        /// </summary>
        public static void SaveSceneNodeCanvas(string saveName, ref NodeCanvas nodeCanvas, bool createWorkingCopy)
        {
            if (string.IsNullOrEmpty(saveName))
            {
                Debug.LogError("Cannot save Canvas to scene: No save name specified!");
                return;
            }

                #if UNITY_EDITOR // Make sure the canvas has no reference to an asset
            if (!createWorkingCopy && UnityEditor.AssetDatabase.Contains(nodeCanvas))
            {
                Debug.LogWarning("Forced to create working copy of '" + saveName + "' when saving to scene because it already exists as an asset!");
                nodeCanvas = CreateWorkingCopy(nodeCanvas, true);
            }
                #endif
            nodeCanvas.livesInScene = true;
            nodeCanvas.name         = saveName;

            // Get the saveHolder and the find the existing stored save or create a new one
            NodeCanvasSceneSave sceneSave = FindSceneSave(saveName);
            if (sceneSave == null)
            {
                sceneSave = sceneSaveHolder.AddComponent <NodeCanvasSceneSave> ();
            }

            // Store the canvas and editor states or optionally their working copies
            sceneSave.savedNodeCanvas = nodeCanvas;
            if (createWorkingCopy)
            {
                sceneSave.savedNodeCanvas = CreateWorkingCopy(sceneSave.savedNodeCanvas, true);
                Compress(ref sceneSave.savedNodeCanvas);
            }

                #if UNITY_EDITOR
            nodeCanvas.BeforeSavingCanvas();
            UnityEditor.EditorUtility.SetDirty(sceneSaveHolder);
                #endif
        }