**异步加载时,加载到90%程序无响应,不是每次都会出现,有时一直不出现,一旦出现了可能好几次重启程序重启电脑都好不了。
代码如下:
**
using System.Collections;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
/*
异步加载控制
*/
public class AsyncLoading_Ctl : MonoBehaviour
{
Image fillImage;
TextMeshProUGUI progressTxt;
AsyncOperation operation;
private void Start()
{
fillImage = transform.Find("FillImage").GetComponent<Image>() ;
progressTxt = transform.Find("ProgressTxt").GetComponent<TextMeshProUGUI>();
StartCoroutine("LoadScene");
//判断进入游戏
AppConst.isLogin = true;
}
IEnumerator LoadScene()
{
yield return new WaitForSeconds(2);
operation = SceneManager.LoadSceneAsync("MainScene");
//while (true)//偶尔卡死
//{
// fillImage.fillAmount = operation.progress;
// progressTxt.text = operation.progress * 100 + "%";
// yield return null;
//}
while (!operation.isDone)//偶尔卡死
{
fillImage.fillAmount = operation.progress;
progressTxt.text = operation.progress * 100 + "%";
yield return null;
}
}
}