在其他地方看到所謂的實時更新就是 讓slider的當前value等於異步對象的進度值而已,太坑了,這個正常來理解的意思不就是從0開始遞增到100嘛,不管怎么我已經完成這個功能了,代碼貼上,以免日后忘記, 找到這篇博客的朋友算你好運,直接搬走吧(NGUI版)~
需要重點提醒的:異步對象AsyncOperation的值到90%后不會再增長,剩下的10%要讓AsyncOperation.allowSceneActivation(意思是場景加載完畢后自動跳轉場景)為true時才會自動完成~
完整代碼下方貼上:
using UnityEngine;
using System.Collections;
public class Loading : MonoBehaviour {
private AsyncOperation async;
public UISlider slider;
// Use this for initialization
void Start ()
{
StartCoroutine (loadScene ());
}
// Update is called once per frame
void Update () {
if (async != null)
{
if(!async.isDone)
{
if(slider.value<=.9f)
{
if(slider.value <= async.progress)
{
slider.value += Time.deltaTime;
}
}
else
{
if(slider.value<1f)
{
slider.value += Time.deltaTime;
}
else
{
async.allowSceneActivation = true;
}
}
}
}
}
IEnumerator loadScene()
{
async = Application.LoadLevelAsync (Globe.loadName);
async.allowSceneActivation = false;
yield return async;
}
