进度条的制作unity
2021-07-01 17:07
标签:game slider ++ ESS loading percent manage unit load 不说了直接上代码: LoadingPanel: using UnityEngine; int toProcess; private int nowProcess; public void Start() StartCoroutine(loadScene(sceneName)); toProgress = 100; } 到时候直接调用LoadingPanel的EnterGame方法就行 进度条的制作unity 标签:game slider ++ ESS loading percent manage unit load 原文地址:https://www.cnblogs.com/mcyushao/p/9636438.html
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LoadingPanel : MonoBehaviour
{
public Slider processBar;
public Image loadingBg;
private AsyncOperation async;
{
loadingBg.sprite = BackgroundShow.Instance.ShowBackground();
}
public void EnterGame(string sceneName)
{
}
private IEnumerator loadScene(string sceneName)
{
int displayProgress = 0;
int toProgress = 0;
AsyncOperation op = SceneManager.LoadSceneAsync(sceneName);
op.allowSceneActivation = false;
while (op.progress {
toProgress = (int)op.progress * 100;
while (displayProgress {
++displayProgress;
SetLoadingPercentage(displayProgress);
yield return new WaitForEndOfFrame();
}
}
while (displayProgress {
++displayProgress;
SetLoadingPercentage(displayProgress);
yield return new WaitForEndOfFrame();
}
op.allowSceneActivation = true;
}
public void SetLoadingPercentage(int value)
{
processBar.value = value / 100f;
}