/// <summary> /// Loads the nodeCanvas and it's editorState stored in the current scene under the specified name and, if specified, creates working copies before returning /// </summary> public static NodeCanvas LoadSceneNodeCanvas(string saveName, bool createWorkingCopy) { if (string.IsNullOrEmpty(saveName)) { Debug.LogError("Cannot load Canvas from scene: No save name specified!"); return(null); } NodeCanvasSceneSave sceneSave = FindSceneSave(saveName); if (sceneSave == null || sceneSave.savedNodeCanvas == null) // No such save file { return(null); } // Extract the saved canvas and editorStates NodeCanvas savedCanvas = sceneSave.savedNodeCanvas; savedCanvas.livesInScene = true; savedCanvas.UpdateSource("SCENE/" + saveName); // Postprocess the loaded canvas ProcessCanvas(ref savedCanvas, createWorkingCopy); #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(sceneSaveHolder); #endif return(savedCanvas); }
/// <summary> /// Returns the scene save with the specified name in the current scene /// </summary> private static NodeCanvasSceneSave FindSceneSave(string saveName, bool forceCreation = false) { string scene = null; #if UNITY_5_3_OR_NEWER || UNITY_5_3 bool sceneSpecified = saveName.Contains("::"); if (sceneSpecified) { string[] sp = saveName.Split(new string[] { "::" }, System.StringSplitOptions.None); scene = sp[0]; saveName = sp[1]; } #endif NodeCanvasSceneSave sceneSave = Object.FindObjectsOfType <NodeCanvasSceneSave>() #if UNITY_5_3_OR_NEWER || UNITY_5_3 // Filter by scene .Where((NodeCanvasSceneSave save) => !sceneSpecified || save.savedNodeCanvas == null || save.gameObject.scene.name == scene) #endif .FirstOrDefault((NodeCanvasSceneSave save) => save.saveName.ToLower() == saveName.ToLower() || (save.savedNodeCanvas != null && save.savedNodeCanvas.name.ToLower() == saveName.ToLower())); if (sceneSave == null && forceCreation) { sceneSave = CreateSceneSave(saveName, scene); } return(sceneSave); }
/// <summary> /// Creates a scene save with the specified name in the current scene /// </summary> private static NodeCanvasSceneSave CreateSceneSave(string saveName, string sceneName = null) { GameObject holder = GetSceneSaveHolder(sceneName); NodeCanvasSceneSave sceneSave = holder.AddComponent <NodeCanvasSceneSave>(); sceneSave.saveName = saveName; return(sceneSave); }
/// <summary> /// Creates a scene save with the specified name in the current scene /// </summary> internal static NodeCanvasSceneSave CreateSceneSave(string saveName) { FetchSceneSaveHolder(); NodeCanvasSceneSave sceneSave = sceneSaveHolder.AddComponent <NodeCanvasSceneSave> (); sceneSave.saveName = saveName; return(sceneSave); }
/// <summary> /// Returns the scene save with the specified name in the current scene /// </summary> internal static NodeCanvasSceneSave FindSceneSave(string saveName) { FetchSceneSaveHolder(); NodeCanvasSceneSave sceneSave = sceneSaveHolder.GetComponents <NodeCanvasSceneSave> ().ToList().Find((NodeCanvasSceneSave save) => save.saveName.ToLower() == saveName.ToLower() || (save.savedNodeCanvas != null && save.savedNodeCanvas.name.ToLower() == saveName.ToLower())); if (sceneSave != null) { sceneSave.saveName = saveName; } return(sceneSave); }
/// <summary> /// Finds a scene save in the current scene with specified name or null if it does not exist /// </summary> internal static NodeCanvasSceneSave FindOrCreateSceneSave(string saveName) { FetchSceneSaveHolder(); NodeCanvasSceneSave sceneSave = sceneSaveHolder.GetComponents <NodeCanvasSceneSave> ().ToList().Find((NodeCanvasSceneSave save) => save.saveName == saveName || save.savedNodeCanvas.name == saveName); if (sceneSave == null) { sceneSave = sceneSaveHolder.AddComponent <NodeCanvasSceneSave> (); } sceneSave.saveName = saveName; return(sceneSave); }
/// <summary> /// Deletes the nodeCanvas stored in the current scene under the specified name /// </summary> public static void DeleteSceneNodeCanvas(string saveName) { if (string.IsNullOrEmpty(saveName)) { return; } NodeCanvasSceneSave sceneSave = FindSceneSave(saveName); if (sceneSave != null) { #if UNITY_EDITOR Object.DestroyImmediate(sceneSave); #else Object.Destroy(sceneSave); #endif } }
/// <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 }
/// <summary> /// Deletes the nodeCanvas and it's editorState stored in the current scene under the specified name /// </summary> public static void DeleteSceneNodeCanvas(string saveName) { if (string.IsNullOrEmpty(saveName)) { Debug.LogError("Cannot delete Canvas from scene: No save name specified!"); return; } NodeCanvasSceneSave sceneSave = FindSceneSave(saveName); if (sceneSave != null) { #if UNITY_EDITOR Object.DestroyImmediate(sceneSave); #else Object.Destroy(sceneSave); #endif //Debug.Log ("Successfully deleted SceneSave " + saveName); } }
/// <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 }
public static NodeCanvas LoadSceneNodeCanvas(string saveName, bool createWorkingCopy) { if (string.IsNullOrEmpty(saveName)) { Debug.LogError("Cannot load Canvas from scene: No save name specified!"); return(null); } NodeCanvasSceneSave nodeCanvasSceneSave = FindSceneSave(saveName); if ((UnityEngine.Object)nodeCanvasSceneSave == (UnityEngine.Object)null) { return(null); } NodeCanvas nodeCanvas = nodeCanvasSceneSave.savedNodeCanvas; nodeCanvas.livesInScene = true; if (createWorkingCopy) { nodeCanvas = CreateWorkingCopy(nodeCanvas, true); } Uncompress(ref nodeCanvas); return(nodeCanvas); }
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!"); } else { nodeCanvas.livesInScene = true; nodeCanvas.name = saveName; NodeCanvasSceneSave nodeCanvasSceneSave = FindSceneSave(saveName); if ((UnityEngine.Object)nodeCanvasSceneSave == (UnityEngine.Object)null) { nodeCanvasSceneSave = sceneSaveHolder.AddComponent <NodeCanvasSceneSave>(); } nodeCanvasSceneSave.savedNodeCanvas = nodeCanvas; if (createWorkingCopy) { nodeCanvasSceneSave.savedNodeCanvas = CreateWorkingCopy(nodeCanvasSceneSave.savedNodeCanvas, true); Compress(ref nodeCanvasSceneSave.savedNodeCanvas); } } }
/// <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); }
/// <summary> /// Returns whether a sceneSave with the specified name exists in the current scene /// </summary> public static bool HasSceneSave(string saveName) { NodeCanvasSceneSave save = FindSceneSave(saveName); return(save != null && save.savedNodeCanvas != null); }
/// <summary> /// Saves the nodeCanvas in the current scene under the specified name, optionally as a working copy and overwriting any existing save at path /// If the specified canvas is stored as an asset, the saved canvas will loose the reference to the asset /// </summary> public static void SaveSceneNodeCanvas(string saveName, ref NodeCanvas nodeCanvas, bool createWorkingCopy, bool safeOverwrite = true) { if (string.IsNullOrEmpty(saveName)) { throw new System.ArgumentNullException("Cannot save Canvas to scene: No save name specified!"); } if (nodeCanvas == null) { throw new System.ArgumentNullException("Cannot save NodeCanvas: The specified NodeCanvas that should be saved as '" + saveName + "' is null!"); } if (nodeCanvas.GetType() == typeof(NodeCanvas)) { throw new System.ArgumentException("Cannot save NodeCanvas: The NodeCanvas has no explicit type! Please convert it to a valid sub-type of NodeCanvas!"); } if (saveName.StartsWith("SCENE/")) { saveName = saveName.Substring(6); } nodeCanvas.Validate(); if (!nodeCanvas.livesInScene #if UNITY_EDITOR // Make sure the canvas has no reference to an asset || UnityEditor.AssetDatabase.Contains(nodeCanvas) #endif ) { Debug.LogWarning("Creating scene save '" + nodeCanvas.name + "' for canvas saved as an asset! Forcing creation of working copy!"); nodeCanvas = CreateWorkingCopy(nodeCanvas); } // Update the source of the canvas nodeCanvas.UpdateSource("SCENE/" + saveName); // Preprocess the canvas NodeCanvas processedCanvas = nodeCanvas; processedCanvas.OnBeforeSavingCanvas(); if (createWorkingCopy) { processedCanvas = CreateWorkingCopy(processedCanvas); } // Get the saveHolder and store the canvas NodeCanvas savedCanvas = processedCanvas; NodeCanvasSceneSave sceneSave = FindSceneSave(saveName, true); #if UNITY_EDITOR if (sceneSave.savedNodeCanvas != null && safeOverwrite && sceneSave.savedNodeCanvas.GetType() == savedCanvas.GetType()) // OVERWRITE { OverwriteCanvas(ref sceneSave.savedNodeCanvas, savedCanvas); } if (!Application.isPlaying) { // Set Dirty UnityEditor.EditorUtility.SetDirty(sceneSave.gameObject); #if UNITY_5_3_OR_NEWER || UNITY_5_3 UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(sceneSave.gameObject.scene); #else UnityEditor.EditorApplication.MarkSceneDirty(); #endif } #endif sceneSave.savedNodeCanvas = savedCanvas; NodeEditorCallbacks.IssueOnSaveCanvas(savedCanvas); }