標籤:style blog color io ar for div art sp
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; } }}
比較簡單,直接上代碼了,比較坑爹的地方做了注釋~
Unity非同步載入情境loading條