进度条的制作unity

2021-07-01 17:07

阅读:627

标签:game   slider   ++   ESS   loading   percent   manage   unit   load   

不说了直接上代码:

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 {
toProgress = (int)op.progress * 100;
while (displayProgress {
++displayProgress;
SetLoadingPercentage(displayProgress);
yield return new WaitForEndOfFrame();
}
}

toProgress = 100;
while (displayProgress {
++displayProgress;
SetLoadingPercentage(displayProgress);
yield return new WaitForEndOfFrame();
}
op.allowSceneActivation = true;
}
public void SetLoadingPercentage(int value)
{
processBar.value = value / 100f;
}

}

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

 

进度条的制作unity

标签:game   slider   ++   ESS   loading   percent   manage   unit   load   

原文地址:https://www.cnblogs.com/mcyushao/p/9636438.html


评论


亲,登录后才可以留言!