捕鱼项目中的
public class LoadGame : MonoBehaviour
{
public Slider processView;
// Use this for initialization
void Start () {
LoadGameMethod();
}
// Update is called once per frame
void Update () {
}
public void LoadGameMethod()
{
StartCoroutine(StartLoading_4(2));
}
private IEnumerator StartLoading_4(int scene)
{
int displayProgress = 0;
int toProgress = 0;
AsyncOperation op = SceneManager.LoadSceneAsync(scene);
//设置成true进度条,走到0.9,加载完不能自动跳到场景
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();
}
//后边百分之10的进度非常快,直接设置为true
op.allowSceneActivation = true;
}
private void SetLoadingPercentage(float v)
{
processView.value = v / 100;
}
}