public void LoadByName(string sceneName,
                        WaitLoadSceneCallback waitLoadSceneCallback = null, LoadingSceneCallback loadingSceneCallback = null, LoadedSceneCallback loadedSceneCallback = null)
 {
     StartCoroutine(WaitForLoadScenePassEmpty(sceneName, waitLoadSceneCallback, loadingSceneCallback, loadedSceneCallback));
 }
    protected IEnumerator WaitForLoadScenePassEmpty(string targetScene,
                                                    WaitLoadSceneCallback waitLoadSceneCallback = null, LoadingSceneCallback loadingSceneCallback = null, LoadedSceneCallback loadedSceneCallback = null)
    {
        this.waitLoadSceneCallback = waitLoadSceneCallback;
        this.loadingSceneCallback  = loadingSceneCallback;
        this.loadedSceneCallback   = loadedSceneCallback;

        yield return(null);

        if (LoadingScene != targetScene)
        {
            LoadingScene = targetScene;
            //异步等待加载空场景
            yield return(DynaLoadScene(ESceneType.EmptyScene.ToString()));

            mAsync = SceneManager.LoadSceneAsync(ESceneType.EmptyScene.ToString());

            yield return(mAsync);

            yield return(CSAssist.waitForEndOfFrame);

            //如果存在开始加载真正场景之前的操作,那么在回调返回true之前,不进行下一步
            if (waitLoadSceneCallback != null)
            {
                while (waitLoadSceneCallback() == false)
                {
                    yield return(CSAssist.waitForEndOfFrame);
                }
            }

            //开始加载真正需要的场景
            mAsync = SceneManager.LoadSceneAsync(targetScene.ToString());
            mAsync.allowSceneActivation = false;

            yield return(null);

            while (!mAsync.isDone && mAsync.allowSceneActivation == false)
            {
                if (mAsync.progress < 0.9f)
                {
                    if (loadingSceneCallback != null)
                    {
                        loadingSceneCallback(mAsync.progress);
                    }
                    yield return(null);
                }
                else
                {
                    mAsync.allowSceneActivation = true;
                    break;
                }
            }
            yield return(mAsync);

            if (mAsync.isDone)
            {
                if (loadedSceneCallback != null)
                {
                    loadedSceneCallback();
                }
            }
        }
        else
        {
            if (CSDebug.developerConsoleVisible)
            {
                CSDebug.LogError("you try to load the same Scene = " + LoadingScene);
            }
        }
    }
 public void Load(ESceneType targetScene,
                  WaitLoadSceneCallback waitLoadSceneCallback = null, LoadingSceneCallback loadingSceneCallback = null, LoadedSceneCallback loadedSceneCallback = null)
 {
     LoadByName(targetScene.ToString(), waitLoadSceneCallback, loadingSceneCallback, loadedSceneCallback);
 }