using UnityEngine;
using System.Collections;

public class LoadingScene : MonoBehaviour {

    public UISlider processBar;
    private AsyncOperation async;
    private uint _nowprocess;
    // Use this for initialization
    void Start () 
    {
        _nowprocess = 0;
        StartCoroutine(loadScene());
    }

    IEnumerator loadScene()
    {
        //异步读取场景。
        //Globe.loadName 就是A场景中需要读取的C场景名称。
        async = Application.LoadLevelAsync(GlobalVaule.LoadLevelName);
        async.allowSceneActivation = false;
         //读取完毕后返回, 系统会自动进入C场景
         yield return async;
        
    }

    void Update()
    {
        if(async == null)
        {
            return;
        }

        uint toProcess;
        Debug.Log(async.progress * 100);
        if(async.progress < 0.9f)//坑爹的progress,最多到0.9f
        {
              toProcess = (uint)(async.progress * 100);
        }
        else
        {
             toProcess = 100;
        }

        if(_nowprocess < toProcess)
        {
            _nowprocess++;
        }

        processBar.value = _nowprocess/100f;

        if (_nowprocess == 100)//async.isDone应该是在场景被激活时才为true
        {
            async.allowSceneActivation = true;
        }
    }

}

比较简单,直接上代码了,比较坑爹的地方做了注释~

相关文章:

  • 2021-09-03
  • 2021-11-16
  • 2022-02-04
  • 2021-11-01
  • 2022-01-05
  • 2021-04-03
  • 2022-12-23
  • 2021-12-12
猜你喜欢
  • 2021-12-26
  • 2021-12-04
  • 2021-12-28
  • 2022-12-23
  • 2022-01-23
  • 2022-01-13
相关资源
相似解决方案