Unity非同步載入情境loading條

來源:互聯網
上載者:User

標籤:style   blog   color   io   ar   for   div   art   sp   

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

比較簡單,直接上代碼了,比較坑爹的地方做了注釋~

Unity非同步載入情境loading條

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.