Unity异步加载

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

///
/// 从主场景跳转到下一个场景
///
public class SliderScriptBoss : MonoBehaviour {
private Slider slid;
private Text txt;
AsyncOperation async;
float progress = 0;
private void Start()
{
slid = GameObject.Find("Slider").GetComponent();
txt = GameObject.Find("Text").GetComponent();
StartCoroutine(LoadScene());
slid.minValue = 0;
slid.maxValue = 1;
txt.color = Color.white;
txt.fontSize = 50;
}
private IEnumerator LoadScene()
{
async = SceneManager.LoadSceneAsync("Fuben_biwuchang_zhandouchangjing");
//这个是加载完毕是否跳转
async.allowSceneActivation = false;
yield return async;
//这个是加载的进度
//async.progress
}
private void Update()
{
if (async.progress >= 0.89f)
{
progress = 1;
}
else
{
progress = async.progress;
}
if (Mathf.RoundToInt(slid.value * 100) == 100)
{
txt.text = "100%";
async.allowSceneActivation = true;
Resources.Load("");
}
else
{
slid.value = Mathf.Lerp(slid.value, progress, Time.deltaTime);
if (slid.value < 0.10f)
{
txt.text = (slid.value * 100).ToString().Substring(0, 1) + "%";
}

else
{
txt.text = (slid.value * 100).ToString().Substring(0, 2) + "%";
}
}
}
}

你可能感兴趣的:(Unity异步加载)