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(); ProcessCanvas(ref nodeCanvas, createWorkingCopy); nodeCanvas.livesInScene = false; UnityEditor.AssetDatabase.CreateAsset(nodeCanvas, path); AddSubAssets(nodeCanvas.editorStates, nodeCanvas); foreach (Node node in nodeCanvas.nodes) { AddSubAsset(node, nodeCanvas); AddSubAssets(node.GetScriptableObjects(), node); foreach (NodeKnob knob in node.nodeKnobs) { 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 }
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 || UnityEditor.AssetDatabase.Contains(nodeCanvas) #endif ) { nodeCanvas = CreateWorkingCopy(nodeCanvas, true); } else { nodeCanvas.Validate(); } nodeCanvas.livesInScene = true; nodeCanvas.name = saveName; #if UNITY_EDITOR nodeCanvas.BeforeSavingCanvas(); #endif NodeCanvas savedCanvas = nodeCanvas; ProcessCanvas(ref savedCanvas, createWorkingCopy); NodeCanvasSceneSave sceneSave = FindSceneSave(saveName); if (sceneSave == null) { sceneSave = sceneSaveHolder.AddComponent <NodeCanvasSceneSave>(); } sceneSave.savedNodeCanvas = savedCanvas; #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(sceneSaveHolder); #endif }