zoukankan      html  css  js  c++  java
  • 异步加载场景并且显示进度条

    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;
            }
        }
    }

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

  • 相关阅读:
    汇编-实验9
    Starling开源手势库AcheGesture
    Robotlegs2的Starling扩展
    Flash Builder 4.6/4.7 注释以及字体大小修改
    js中函数的理解
    js对象引用赋值后
    var声明提前 undefined
    光棍节程序员闯关秀
    body和普通div背景图宽高百分比的区别
    笔试题
  • 原文地址:https://www.cnblogs.com/qinshuaijun/p/8559438.html
Copyright © 2011-2022 走看看