码迷,mamicode.com
首页 > 编程语言 > 详细

进度条的制作unity

时间:2018-09-12 19:55:28      阅读:204      评论:0      收藏:0      [点我收藏+]

标签: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 < 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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!