您的位置:首页 > 移动开发 > Unity3D

Unity3D LoadingScene

2014-11-22 11:43 239 查看

Unity3D LoadingScene

大家都知道,在我们玩游戏的时候,在进入游戏的时候,都会看到会有一个进度条画面,这样做是因为场景加载的需要一定时间,尤其是场景资源很大的时候,都是通过引入一个过渡画面,显示游戏加载进度,这样提高了游戏的体验度。

using UnityEngine;

using System.Collections;

public class LoadingScene : MonoBehaviour

{

public UISlider processBar;//进度条

private AsyncOperation async;

private uint _nowprocess;

// Use this for initialization

void Start()

{

_nowprocess = 0;

StartCoroutine(loadScene());

}

IEnumerator loadScene()

{

//异步读取场景。

async = Application.LoadLevelAsync("Scenename");

async.allowSceneActivation = false;

//读取完毕后返回,系统会自动进入目标场景

yield return async;

}

void Update()

{

if (async == null)

{

return;

}

uint toProcess;

Debug.Log(async.progress * 100);

if (async.progress < 0.9f)

{

toProcess = (uint)(async.progress * 100);

}

else

{

toProcess = 100;

}

if (_nowprocess < toProcess)

{

_nowprocess++;

}

processBar.value = _nowprocess / 100f;

if (_nowprocess == 100)

{

async.allowSceneActivation = true;

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: