U_场景异步加载 Loading


        IEnumerator<string> LoadScene(string name, Slider slider, TextMeshProUGUI text) {
            yield return null;

            AsyncOperation operation = Loader.Loader.LoadSceneAsync(name);
            operation.completed += asyncOperation => Debug.Log("Load scene completed!");
            operation.allowSceneActivation = false;
            float progress = 0;
            while (!operation.isDone) {
                progress = Mathf.MoveTowards(progress, operation.progress, Time.deltaTime);
                slider.value = progress;
                text.text = string.Concat("加载中...", operation.progress * 100, "%");
                if (progress >= 0.9f) {
                    slider.value = 1;
                    operation.allowSceneActivation = true;
                }
                yield return null;
            }
        }

posted @ 2023-11-01 17:14  匿鱼  阅读(119)  评论(0)    收藏  举报