进度条的制作unity

Posted mcyushao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了进度条的制作unity相关的知识,希望对你有一定的参考价值。

不说了直接上代码:

LoadingPanel:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LoadingPanel : MonoBehaviour
{
public Slider processBar;
public Image loadingBg;

int toProcess;
private AsyncOperation async;

private int nowProcess;

public void Start()
{
loadingBg.sprite = BackgroundShow.Instance.ShowBackground();
}
public void EnterGame(string sceneName)
{

StartCoroutine(loadScene(sceneName));
}
private IEnumerator loadScene(string sceneName)
{
int displayProgress = 0;
int toProgress = 0;
AsyncOperation op = SceneManager.LoadSceneAsync(sceneName);
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;
}
public void SetLoadingPercentage(int value)
{
processBar.value = value / 100f;
}

}

到时候直接调用LoadingPanel的EnterGame方法就行

 















































以上是关于进度条的制作unity的主要内容,如果未能解决你的问题,请参考以下文章

前端页面加载进度条的制作

Python的进度条的制作

Python的进度条的制作

# 进度条的制作

进度条的制作-python

进度条的制作