• 异步加载场景并且显示进度条


    using System.Collections;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    using UIWidgets;
    using UnityEngine.UI;
    
    namespace GameScene
    {
        public class LoadingSync : MonoBehaviour
        {
            private static string NextSceneName = "";
           
            public static void EnterScene(string name)
            {
                NextSceneName = name;
                SceneManager.LoadScene("LoadingSync");
            }
    
            //异步对象
            public Slider LoadingSlider;
            public Text LoadingText;
            private int displayProgress = 0;
            // Use this for initialization
            void Awake()
            {
    
            }
            void Start()
            {
                StartCoroutine(LoadScene());   
            }
    
            IEnumerator LoadScene()
            {
                Debug.Log("EnterScene:" + NextSceneName);
                LoadingSlider.value = 0;
                LoadingText.text = "0%";
                yield return new WaitForEndOfFrame();
                AsyncOperation op = SceneManager.LoadSceneAsync(NextSceneName);
                op.allowSceneActivation = false;
                while (op.progress < 0.9f) {
                    displayProgress = (int)(op.progress * 100);
                    while (LoadingSlider.value < displayProgress) {
                        LoadingSlider.value++;
                        LoadingText.text = ((int)(LoadingSlider.value)).ToString()+"%";
                        yield return null;
                    }
                    yield return null;
                }
                displayProgress = 100;
                while (LoadingSlider.value < displayProgress) {
                    LoadingSlider.value++;
                    LoadingText.text = ((int)(LoadingSlider.value)).ToString() + "%";
                    yield return null;
                }
                LoadingText.text = "100%";
                op.allowSceneActivation = true;
            }
        }
    }

      等到进度条显示完啦场景在加载出来

  • 相关阅读:
    今天的进度又慢了
    继续还有一些基本功能
    没什么事情
    今天好冷啊
    估计下周一就不去了
    再次出发
    诡异的php curl error Empty reply from server
    postgresql interval 字段拼接
    使用root用户通过SSH登录Linux实例时报“Permission denied, please try again”的错误
    pgsql 记录类型
  • 原文地址:https://www.cnblogs.com/qinshuaijun/p/8559438.html
Copyright © 2020-2023  润新知