流星

坚持住才有机会.

Unity进度条卡死 有更新!

    网上大部分来源都是如下代码
    这个代码会引起导出Android包时,加载场景卡死

    public void Load(int id)
    {
    	StartCoroutine("LoadLevelAsync", id);
    }
    
    IEnumerator LoadLevelAsync(int levelId)
    {
    	int displayProgress = 0;
    	int toProgress = 0;
    	yield return new WaitForEndOfFrame();
    	Level lev = LevelMng.Instance.GetItem(levelId);
    	mAsync = SceneManager.LoadSceneAsync(lev.Scene);
    	mAsync.allowSceneActivation = false;
    	while (mAsync.progress < 0.9f)
    	{
    		toProgress = (int)mAsync.progress * 100;
    		while (displayProgress < toProgress)
    		{
    			++displayProgress;
    			LoadingWnd.Instance.UpdateProgress(displayProgress);
    			yield return new WaitForEndOfFrame();
    		}
    		yield return new WaitForEndOfFrame(); //注意如果少了这句话,就是死循环
    	}
    	toProgress = 100;
    	while (displayProgress < toProgress)
    	{
    		++displayProgress;
    		LoadingWnd.Instance.UpdateProgress(displayProgress);
    		yield return new WaitForEndOfFrame();
    	}
    	mAsync.allowSceneActivation = true;
    	yield return new WaitForEndOfFrame();
    	OnLoadFinishedEx(lev);
    }
    

    这个问题会导致有几率发生死循环
    加上那句后面带注释的话,就不会死循环了

    validate