/// <summary> /// Called when the user requests that the editor shuts down. You must manually close the editor from this /// method if you choose to accept the users request. /// </summary> static void OnEditorQuitRequested() { Action <DialogBox.ResultType> dialogCallback = (result) => { if (result == DialogBox.ResultType.Yes) { TrySaveScene(); } else if (result == DialogBox.ResultType.No) { EditorApplication.SaveProject(); EditorApplication.Quit(); } }; if (EditorApplication.IsSceneModified()) { DialogBox.Open("Warning", "You current scene has modifications. Do you wish to save them first?", DialogBox.Type.YesNoCancel, dialogCallback); } else { EditorApplication.SaveProject(); EditorApplication.Quit(); } }
/// <summary> /// Attempts to save the current scene, and keeps retrying if failed or until user cancels. /// </summary> static void TrySaveScene() { Action success = () => { EditorApplication.SaveProject(); EditorApplication.Quit(); }; EditorApplication.SaveScene(success, TrySaveScene); }
/// <summary> /// Triggered when the user clicks the cancel button. /// </summary> void CancelClicked() { if (EditorApplication.IsProjectLoaded) { Close(); // Just close the window } else { EditorApplication.Quit(); // Close the application, we cannot do anything without a project } }