コード例 #1
0
    private IEnumerator <float> LoadScene_Coroutine(string scene, Action callback)
    {
        //Unload other scene
        if (currentSceneScript != null)
        {
            currentSceneScript.OnSceneStop();
            UnityEngine.SceneManagement.SceneManager.UnloadSceneAsync(currentScene);
            currentSceneScript = null;
        }

        AsyncOperation asyncOp = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(scene, UnityEngine.SceneManagement.LoadSceneMode.Additive);

        yield return(Timing.WaitUntilDone(asyncOp));

        currentScene = UnityEngine.SceneManagement.SceneManager.GetSceneByName(scene);
        GameObject sceneGO = currentScene.GetRootGameObjects().Where((arg1) => arg1.GetComponentInChildren <BRScene>() != null).FirstOrDefault();

        if (sceneGO != null)
        {
            currentSceneScript = sceneGO.GetComponentInChildren <BRScene>();
        }
        else
        {
            Debug.LogException(new SceneManagerLoadException(scene, "Scene does not have a root object with a script extending BRScene..."));
        }

        callback?.Invoke();
    }
コード例 #2
0
    protected override void OnDestroy()
    {
        base.OnDestroy();

        if (currentSceneScript != null)
        {
            currentSceneScript.OnSceneStop();
            currentSceneScript = null;
        }
    }