zoukankan      html  css  js  c++  java
  • 异步加载

    引自:http://www.cnblogs.com/wonderKK/p/3976213.html

    using UnityEngine;
    using System.Collections;
    
    public class LoadingScene : MonoBehaviour {
    
        public UISlider processBar;
        private AsyncOperation async;
        private uint _nowprocess;
        // Use this for initialization
        void Start () 
        {
            _nowprocess = 0;
            StartCoroutine(loadScene());
        }
    
        IEnumerator loadScene()
        {
            //异步读取场景。
            //Globe.loadName 就是A场景中需要读取的C场景名称。
            async = Application.LoadLevelAsync(GlobalVaule.LoadLevelName);
            async.allowSceneActivation = false;
             //读取完毕后返回, 系统会自动进入C场景
             yield return async;
            
        }
    
        void Update()
        {
            if(async == null)
            {
                return;
            }
    
            uint toProcess;
            Debug.Log(async.progress * 100);
            if(async.progress < 0.9f)//坑爹的progress,最多到0.9f
            {
                  toProcess = (uint)(async.progress * 100);
            }
            else
            {
                 toProcess = 100;
            }
    
            if(_nowprocess < toProcess)
            {
                _nowprocess++;
            }
    
            processBar.value = _nowprocess/100f;
    
            if (_nowprocess == 100)//async.isDone应该是在场景被激活时才为true
            {
                async.allowSceneActivation = true;
            }
        }
    
    }
  • 相关阅读:
    Spring Boot的每个模块包详解
    spring框架所有包说明
    TCP三次握手和四次挥手
    线程池实现原理
    AVL树与红黑树
    去哪儿网面经
    什么是缓存一致性问题?如何解决?
    Redis的应用场景和优缺点
    线程池
    手写快排
  • 原文地址:https://www.cnblogs.com/naiking/p/4206790.html
Copyright © 2011-2022 走看看