简体   繁体   English

Unity EditorWindow-更改场景时保存弹出窗口

[英]Unity EditorWindow - Save popup while changing scenes

So I am making a kind of Scene Management in my EditorWindow, I was wondering if there is any way of giving the same popup when you try to change the current unsaved scene as you get in the normal way? 因此,我正在EditorWindow中进行一种“场景管理”,我想知道当您尝试以正常方式更改当前未保存的场景时,是否有任何方法可以弹出相同的弹出窗口?

在此处输入图片说明

if(GUILayout.Button("Main Menu"))
{           
    EditorSceneManager.OpenScene("Assets/_Scenes/00MainMenu.unity");
}

if(GUILayout.Button("Level01"))
{
    EditorSceneManager.OpenScene("Assets/_Scenes/01Level.unity");
}

For all currently opened scenes you can use eg EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo like 对于所有当前打开的场景,您可以使用例如EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo喜欢

if(GUILayout.Button("Main Menu"))
{   
    if(EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
    {
        // user said yes -> scene was saved
        EditorSceneManager.OpenScene("Assets/_Scenes/00MainMenu.unity");
    }
    else
    {
        // user said no -> evtl. abort or do nothing?
    }
}

if(GUILayout.Button("Level01"))
{
    if(EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
    {
        // user said yes -> scene was saved
        EditorSceneManager.OpenScene("Assets/_Scenes/01Level.unity");
    }
    else
    {
        // user said no -> evtl. abort or do nothing?
    }
}

However note Unity's little hint ^^ 但是请注意Unity的一点提示^^

Note: Currently a window with three buttons is shown. 注意:当前显示带有三个按钮的窗口。 Save and /Don't Save/ both cause the Scene(s) to be written. 保存和/不保存/都会导致场景被写入。 Cancel leaves the Scene(s) untouched. 取消使场景保持不变。


Alternatively you could also use EditorSceneManager.SaveModifiedScenesIfUserWantsTo in order to limit the saving to a certain array of scenes. 或者,您也可以使用EditorSceneManager.SaveModifiedScenesIfUserWantsTo来将保存限制为特定的场景数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM