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; } } }
比較簡單,直接上代碼了,比較坑爹的地方做了注釋~