Unity 异步加载进度条

 public class View_LoadingScene : MonoBehaviour
{
//场景加载进度条对象
public GameObject loadingProgressBar;
//进度条组件
private Slider _loadingProgressBarComp;
//当前进度值
private float _curProgressValue = 0f; private AsyncOperation _asyncOp;
private void Awake()
{
if(loadingProgressBar != null)
{
//获取进度条组件
_loadingProgressBarComp = loadingProgressBar.GetComponent<Slider>();
}
}
private void Start()
{ StartCoroutine("LoadingLevelAsync");
}
private void Update()
{
//模拟加载进度
if(_loadingProgressBarComp.value <= 1f)
{
SimulateLoad();
}
_loadingProgressBarComp.value = _curProgressValue; } private void SimulateLoad()
{
_curProgressValue += 0.01f;
} //异步加载核心函数
IEnumerator LoadingLevelAsync()
{
_asyncOp = SceneManager.LoadSceneAsync("2_LogonScene");
_curProgressValue = _asyncOp.progress;
yield return _asyncOp;
}
}
上一篇:unity中实现场景之间加载进度条


下一篇:js页面加载进度条