public static bool SaveAs() { var persistentObject = EditorContext.PersistentObject; var extension = UTinyPersistence.GetFileExtension(persistentObject); var path = EditorUtility.SaveFilePanelInProject($"Save {ContextType}", persistentObject.Name, extension.Substring(1), string.Empty); if (string.IsNullOrEmpty(path)) { return(false); } // Use a DontSaveScope since saving may trigger the `OnWillSaveAssets` callback using (new UTinyModificationProcessor.DontSaveScope()) { // Fix-up the name persistentObject.Name = Path.GetFileNameWithoutExtension(path); // Flush the caretaker so this operation is not undoable EditorContext.Caretaker.Update(); path = UTinyPersistence.PersistObjectAs(persistentObject, path); if (string.IsNullOrEmpty(path)) { return(false); } } UTinyEditorPrefs.SaveWorkspace(EditorContext.Workspace, persistentObject.PersistenceId); OnSaveProject?.Invoke(EditorContext.Project); UTinyModificationProcessor.ClearChanged(); return(true); }
/// <summary> /// Saves the current project or module to the assets directory /// /// NOTE: If the project has never been saved before a `Save As` is called instead /// </summary> public static bool Save() { var persistentObject = EditorContext.PersistentObject; // No `PersistenceId` means this object has never been saved, promt the user with the `Save As` instead if (string.IsNullOrEmpty(persistentObject.PersistenceId)) { return(SaveAs()); } // Use a DontSaveScope since saving may trigger the `OnWillSaveAssets` callback using (new UTinyModificationProcessor.DontSaveScope()) { var path = UTinyPersistence.PersistObject(persistentObject); if (string.IsNullOrEmpty(path)) { return(false); } } UTinyEditorPrefs.SaveWorkspace(EditorContext.Workspace, persistentObject.PersistenceId); OnSaveProject?.Invoke(EditorContext.Project); UTinyModificationProcessor.ClearChanged(); return(true); }