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;
}
}