官方Unity SaveCurrentModifiedScenesIfUserWantsTo 的使用实例,在主菜单上添加一个菜单项 Examples, 菜单项下面有一个菜单 Save current Scene(s) if require。此方法不能在Play mode 存储Scene。
// 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)");
}
}
}