码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-02-20 01:28:41      阅读:350      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!