异步加载async实现loading
UISprite loadingUI;//loading进度条UI
UILabel loadingLabel;//loading显示文本
AsyncOperation async;//异步对象
void Start () {
loadingUI = GetComponent<UISprite>();
loadingUI.fillAmount = 0;
loadingLabel = GetComponentInChildren<UILabel>();
StartCoroutine (LoadScene ());//协程,进入LoadScene方法
}
void Update () {
loadingUI.fillAmount = async.progress;//将进度值赋给ui的填充值
loadingLabel.text = string.Format("Loading {0}%",(int)(async.progress*100));
}
IEnumerator LoadScene () {
async = Application.LoadLevelAsync(Global.GetInstance().loadName);//异步读取场景
yield return async;//读取完毕后,系统自动进入读取的游戏场景
}
- 下一篇:unity3d数据持久化
- 上一篇:也说AR(高通vuforia+unity)