using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Script_LoadSceneAsync : MonoBehaviour
{
public static Script_LoadSceneAsync Instance;
Slider progress_slider;
Text progress_text;
void Awake()
{
Instance = this;
if (Instance == null)
Instance = this;
}
public void LoadSceneAsyncFun(string SceneName)
{
GameObject PROCanvas = Instantiate(Resources.Load<GameObject>("Prefab/PROCanvas"));
progress_text = PROCanvas.GetComponentInChildren<Text>();
progress_slider = PROCanvas.GetComponentInChildren<Slider>();
StartCoroutine(LoadSceneAsyncFunction(SceneName));
}
IEnumerator LoadSceneAsyncFunction(string SceneName)
{
int disableProgress = 0;
int Progress = 0;
AsyncOperation Aop = SceneManager.LoadSceneAsync(SceneName);
Aop.allowSceneActivation = false;
while (Aop.progress < 0.9f)
{
Progress = (int)(Aop.progress * 100);
while (disableProgress < Progress)
{
++disableProgress;
progress_slider.value = disableProgress / 100.0f;
yield return new WaitForEndOfFrame();
}
}
Progress = 100;
while (disableProgress < Progress)
{
++disableProgress;
progress_slider.value = disableProgress / 100.0f;
yield return new WaitForEndOfFrame();
}
Aop.allowSceneActivation = true;
}
private void Update()
{
if (progress_slider != null)
{
progress_text.text = (progress_slider.value * 100).ToString("0") + "%";
}
}
}
不收积分 下载地址:LoadSceneAsync.rar
|