游戏关卡加载,有时就是加载一个一个的场景,那么怎么合理加载场景呢,主要思路如下:
using UnityEngine;
using System.Collections;
public class LoadScene : MonoBehaviour {
// Use this for initialization
void Start () {
StartCoroutine(StartLoading_4(3));
}
private IEnumerator StartLoading_4(int scene) {
int displayProgress = 0;
int toProgress = 0;
AsyncOperation op = Application.LoadLevelAsync(scene);
op.allowSceneActivation = false;
while(op.progress < 0.9f)
{
toProgress = (int)(op.progress * 100);
while(displayProgress < toProgress)
{
++displayProgress;
SetLoadingPercentage(displayProgress);
yield return new WaitForEndOfFrame();
}
}
toProgress = 100;
while(displayProgress < toProgress)
{
++displayProgress;
SetLoadingPercentage(displayProgress);
yield return new WaitForEndOfFrame();
}
op.allowSceneActivation = true;
}
private void SetLoadingPercentage(int m)
{
print(m);
}
}