纳金网
标题:
场景切换,unity异步加载,loading条做法
[打印本页]
作者:
刀锋狼
时间:
2015-2-19 22:21
标题:
场景切换,unity异步加载,loading条做法
参考了网上大神的做法,做了一点小改动,效果还不错,给大家分享。
AsyncOperation mAsync; //需要加载的场景
public UISlider LoadingSlider; //NGUI做的
public UILabel GameTip;
// Use this for initialization
void OnEnable()
{
StartCoroutine("LoadScene");
GameTip.text = GameTipsController.Singleton.RandomTip();
}
void OnDisable()
{
StopAllCoroutines();
}
// Update is called once per frame
void Update()
{
}
IEnumerator LoadScene()
{
int displayProgress = 0;
int toProgress = 0;
mAsync = Application.LoadLevelAsync(StaticDataCache.Singleton.CurLoadScene);
mAsync.allowSceneActivation = false;
Debug.Log(mAsync.progress);
while (mAsync.progress < 0.9f)
{
toProgress = (int)mAsync.progress * 100;
while (displayProgress < toProgress)
{
++displayProgress;
SetLoadingSlider(displayProgress);
yield return new WaitForEndOfFrame() ;
}
yield return new WaitForEndOfFrame();
}
toProgress = 100;
while (displayProgress < toProgress)
{
++displayProgress;
SetLoadingSlider(displayProgress);
yield return new WaitForEndOfFrame();
}
mAsync.allowSceneActivation = true;
gameObject.SetActive(false);
}
void SetLoadingSlider(int progress)
{
float tmp = (float)((float)progress / 100);
LoadingSlider.value = tmp;
}
欢迎光临 纳金网 (http://go.narkii.com/club/)
Powered by Discuz! X2.5