Unity异步加载场景loading条

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 = ;
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 * );
if(async.progress < 0.9f)//坑爹的progress,最多到0.9f
{
toProcess = (uint)(async.progress * );
}
else
{
toProcess = ;
} if(_nowprocess < toProcess)
{
_nowprocess++;
} processBar.value = _nowprocess/100f; if (_nowprocess == )//async.isDone应该是在场景被激活时才为true
{
async.allowSceneActivation = true;
}
} }

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

上一篇:场景切换 异步加载 loading条做法


下一篇:Unity关于用LoadLevelAdditiveAsync导致新场景的Navmesh数据不正确Loading条的实践