예제 #1
0
    IEnumerator StartLoadScene(EF_JumpSceneAnim anim)
    {
        LoadManager mLoadManager = Get <LoadManager>(EF_Manager.Load);
        // 1. 加载动画 Prefab
        string             animPath    = ANIM_PREFAB + anim;
        Base_JumpSceneAnim loadingAnim = mLoadManager.LoadPrefab(animPath).GetComponent <Base_JumpSceneAnim>();

        if (null == loadingAnim)
        {
            MyLog.Red("这个是假的动画吧,取不到动画组件 —— " + anim);
            yield break;
        }
        yield return(0);

        // 2. 异步加载场景,手动跳转
        AsyncOperation aso = SceneManager.LoadSceneAsync(mSceneBean.ToString());

        aso.allowSceneActivation = false;

        // 3.加载场景过程
        float displayProgress = 0;                // 这个才是用来显示的进度
        float toProgress      = 0;                // 实际进度

        while (aso.progress < 0.9f)
        {
            if (displayProgress < 1)
            {
                displayProgress += 0.01f;
                mSceneBean.Loading(displayProgress);
            }
            yield return(0);
        }
        yield return(0);

        toProgress = 1;
        while (displayProgress < toProgress)
        {
            if (toProgress - displayProgress >= 0.2f)
            {
                displayProgress += 0.2f;
            }
            else
            {
                displayProgress += 0.5f;
            }
            if (displayProgress <= 1)
            {
                mSceneBean.Loading(displayProgress);
            }
            yield return(0);
        }
        mSceneBean.Loading(1);

        yield return(0);

        // 4.加载完搞动画
        loadingAnim.IsOut = true;
        loadingAnim.OnReady2Do();
        StartCoroutine(loadingAnim.DoLastRenderer());      // 开始渲染


        float time = 0;

        while (loadingAnim.OnProcessAnim(time))                // 开始动画
        {
            time += Time.deltaTime;
            yield return(0);
        }

        yield return(Get <UIManager>(EF_Manager.UI).ChangScene(mCurrentScene));                       // 告诉 UI 切换场景了


        aso.allowSceneActivation = true;                   // 完成动画开始跳场景


        loadingAnim.IsOut = false;                                           // 进入新的场景

        loadingAnim.OnReady2Do();
        time = 0;
        mSceneBean.Enter();                               // 进入这个场景
        while (loadingAnim.OnProcessAnim(time))
        {
            time += Time.deltaTime;
            yield return(0);
        }

        mSceneBean.Start();
        MyEventCenter.SendEvent(E_GameEvent.RealJumpIntoScene, mCurrentScene);
        yield return(0);

        mLoadManager.DestroyPrefabAll(animPath, loadingAnim.gameObject);

        mLoadManager.CLearRes();                          // 删除上一个场景的 Res 资源
        IsAniming = false;
    }