using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UIElements; using KTGMGemClient; public class LoadingScene : MonoBehaviour { public TextMeshProUGUI loadingTxt; private AsyncOperation async = null; protected string dynamicTxt = ""; protected static float UPDATE_TIME = 0.5f; protected float curTime = 0.0f; protected float totalTime = 0.0f; protected bool bLoadScene = false; // Start is called before the first frame update void Start() { loadingTxt.text = "LOADING"; curTime = UPDATE_TIME; } IEnumerator LoadScene() { async = SceneManager.LoadSceneAsync(GameConfig.NextSceneName); async.allowSceneActivation = true; /*while (!async.isDone) { if (async.progress < 0.9f) progressValue = async.progress; else progressValue = 1.0f; slider.value = progressValue; progress.text = (int)(slider.value * 100) + " %"; if (async.progress >= 0.89) { Debug.Log("进展时间分别是:" + async.progress + "," + totalTime); if( totalTime >= 3.0f ) async.allowSceneActivation = true; progress.text = "按任意键继续"; if (Input.anyKeyDown) { async.allowSceneActivation = true; } } //yield return null; }*/ yield return null; } // Update is called once per frame void Update() { float tf = Time.deltaTime; curTime -= tf; if (curTime <= 0) { totalTime += 0.8f; curTime = UPDATE_TIME + curTime; // 更新文字. dynamicTxt += "."; if (dynamicTxt.Length > 6) dynamicTxt = ""; loadingTxt.text = "LOADING" + dynamicTxt; if ((dynamicTxt.Length >= 1) && (!bLoadScene) ) { bLoadScene = true; StartCoroutine("LoadScene"); } } } }