The official Unity SaveCurrentModifiedScenesIfUserWantsTo usage example adds a menu item Examples to the main menu, and there is a menu Save current Scene(s) if require under the menu item. This method cannot store Scene in Play mode.
// Add an editor menu item that enables Scenes to be saved or not,
// This example adds the editor extension into an Examples menu.
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
public class ExampleClass : MonoBehaviour
{
[MenuItem("Examples/Save current Scene(s) if required")]
static void MaybeSaveScenes()
{
EditorSceneManager.SaveOpenScenes();
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
{
Debug.Log("Continue... (Save or Don't Save was clicked)");
}
else
{
Debug.Log("Abort... (Cancel was clicked)");
}
}
}