在Unity3d中重新加载游戏场景而不重新加载UIScene

在Unity3d中重新加载游戏场景而不重新加载UIScene,unity3d,Unity3d,我有两个场景“游戏性”和“游戏界面” 我通过游戏性加载GameUI void Awake () { if (!instance) { instance = this; } else { Destroy(this.gameObject) ; } SceneManager.LoadScene ("GameUI", LoadSceneMode.Additive); DontDestroyOnLoad(this.gameObjec

我有两个场景“游戏性”和“游戏界面”

我通过游戏性加载GameUI

void Awake () {
    if (!instance) {
        instance = this;
    } else {
        Destroy(this.gameObject) ;
    }

    SceneManager.LoadScene ("GameUI", LoadSceneMode.Additive);
    DontDestroyOnLoad(this.gameObject);
}
现在,当我使用

SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

如何防止重新加载“GameUI”场景?

您可以添加一个附加到GameUI的
MonoBehavior
,该GameUI包含一个指示对象是否存在的静态bool。使用以下脚本使整个UI场景成为一个对象的子对象

public class UIExistance : MonoBehaviour
{
    public static bool Exists { get; private set; }

    void Awake()
    {
        DontDestroyOnLoad(transform.gameObject);
        UIExistance.Exists = true;
    }

    void OnDestroy()
    {
        UIExistance.Exists = false;
    }
}
当您使用post
Awake
方法时,您可以使用
检查(!UIExistance.Exists)
UI是否已在场景中