首页 > 其他 > 详细

场景切换 异步加载 loading条做法

时间:2015-02-20 01:25:28      阅读:284      评论:0      收藏:0      [点我收藏+]

 AsyncOperation mAsync; //需要加载的场景
    public UISlider LoadingSlider; //NGUI做的
    public UILabel GameTip;

     // Use this for initialization
     void OnEnable()
     {
         StartCoroutine("LoadScene");

         GameTip.text = GameTipsController.Singleton.RandomTip();
     }

     void OnDisable()
     {
         StopAllCoroutines();
     }


     // Update is called once per frame
     void Update()
     {
     }

     IEnumerator LoadScene()
     {
         int displayProgress = 0;
         int toProgress = 0;
         mAsync = Application.LoadLevelAsync(StaticDataCache.Singleton.CurLoadScene);
         mAsync.allowSceneActivation = false;
         Debug.Log(mAsync.progress);
         while (mAsync.progress < 0.9f)
         {
             toProgress = (int)mAsync.progress * 100;
             while (displayProgress < toProgress)
             {
                 ++displayProgress;
                 SetLoadingSlider(displayProgress);
                 yield return new WaitForEndOfFrame() ;
             }
             yield return new WaitForEndOfFrame();
         }

         toProgress = 100;
         while (displayProgress < toProgress)
         {
             ++displayProgress;
             SetLoadingSlider(displayProgress);
             yield return new WaitForEndOfFrame();
         }
         mAsync.allowSceneActivation = true;
         gameObject.SetActive(false);

     }

     void SetLoadingSlider(int progress)
     {
         float tmp = (float)((float)progress / 100);
         LoadingSlider.value = tmp;
     }

场景切换 异步加载 loading条做法

原文:http://www.cnblogs.com/softimagewht/p/4296371.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!