/// <summary> /// Loads the NodeCanvas from the asset file at path and optionally creates a working copy of it before returning /// </summary> public static NodeCanvas LoadNodeCanvas(string path, bool createWorkingCopy) { #if !UNITY_EDITOR throw new System.NotImplementedException(); #else if (string.IsNullOrEmpty(path)) { throw new System.ArgumentNullException("Cannot load Canvas: No path specified!"); } path = ResourceManager.PreparePath(path); // Load only the NodeCanvas from the save file NodeCanvas nodeCanvas = ResourceManager.LoadResource <NodeCanvas> (path); if (nodeCanvas == null) { throw new UnityException("Cannot load NodeCanvas: The file at the specified path '" + path + "' is no valid save file as it does not contain a NodeCanvas!"); } if (!Application.isPlaying && (nodeCanvas.editorStates == null || nodeCanvas.editorStates.Length == 0)) { // Try to load any contained editorStates, as the canvas did not reference any nodeCanvas.editorStates = ResourceManager.LoadResources <NodeEditorState> (path); } // Set the path as the new source of the canvas nodeCanvas.UpdateSource(path); // Postprocess the loaded canvas nodeCanvas.Validate(); if (createWorkingCopy) { nodeCanvas = CreateWorkingCopy(nodeCanvas); } NodeEditorCallbacks.IssueOnLoadCanvas(nodeCanvas); return(nodeCanvas); #endif }
/// <summary> /// Loads the nodeCanvas stored in the current scene under the specified name and optionally creates a working copy of it before returning /// </summary> public static NodeCanvas LoadSceneNodeCanvas(string saveName, bool createWorkingCopy) { if (string.IsNullOrEmpty(saveName)) { throw new System.ArgumentNullException("Cannot load Canvas from scene: No save name specified!"); } if (saveName.StartsWith("SCENE/")) { saveName = saveName.Substring(6); } // Load SceneSave NodeCanvasSceneSave sceneSave = FindSceneSave(saveName); if (sceneSave == null || sceneSave.savedNodeCanvas == null) { return(null); } // Extract the saved canvas and editorStates NodeCanvas savedCanvas = sceneSave.savedNodeCanvas; // Set the saveName as the new source of the canvas savedCanvas.UpdateSource("SCENE/" + saveName); // Postprocess the loaded canvas savedCanvas.Validate(); if (createWorkingCopy) { savedCanvas = CreateWorkingCopy(savedCanvas); } NodeEditorCallbacks.IssueOnLoadCanvas(savedCanvas); return(savedCanvas); }
public static NodeCanvas LoadNodeCanvas(string path, bool createWorkingCopy) { if (!File.Exists(path)) { throw new UnityException("Cannot Load NodeCanvas: File '" + path + "' deos not exist!"); } NodeCanvas nodeCanvas = ResourceManager.LoadResource <NodeCanvas>(path); if ((UnityEngine.Object)nodeCanvas == (UnityEngine.Object)null) { throw new UnityException("Cannot Load NodeCanvas: The file at the specified path '" + path + "' is no valid save file as it does not contain a NodeCanvas!"); } if (createWorkingCopy) { nodeCanvas = CreateWorkingCopy(nodeCanvas, true); } else { nodeCanvas.Validate(); } Uncompress(ref nodeCanvas); NodeEditorCallbacks.IssueOnLoadCanvas(nodeCanvas); return(nodeCanvas); }
/// <summary> /// Loads the NodeCanvas from the asset file at path and optionally creates a working copy of it before returning /// </summary> public static NodeCanvas LoadNodeCanvas(string path, bool createWorkingCopy) { if (string.IsNullOrEmpty(path)) { throw new UnityException("Cannot Load NodeCanvas: No path specified to load the NodeCanvas from!"); } // Fetch all objects in the save file ScriptableObject[] objects = ResourceManager.LoadResources <ScriptableObject> (path); if (objects == null || objects.Length == 0) { throw new UnityException("Cannot Load NodeCanvas: The specified path '" + path + "' does not point to a save file!"); } // Filter out the NodeCanvas out of these objects NodeCanvas nodeCanvas = objects.Single((ScriptableObject obj) => (obj as NodeCanvas) != null) as NodeCanvas; if (nodeCanvas == null) { throw new UnityException("Cannot Load NodeCanvas: The file at the specified path '" + path + "' is no valid save file as it does not contain a NodeCanvas!"); } #if UNITY_EDITOR // Create a working copy of it if (createWorkingCopy) { CreateWorkingCopy(ref nodeCanvas, false); if (nodeCanvas == null) { throw new UnityException("Cannot Load NodeCanvas: Failed to create a working copy for the NodeCanvas at path '" + path + "' during the loading process!"); } } UnityEditor.AssetDatabase.Refresh(); #endif NodeEditorCallbacks.IssueOnLoadCanvas(nodeCanvas); return(nodeCanvas); }