码迷,mamicode.com
首页 > 编程语言 > 详细

Unity异步加载场景loading条

时间:2015-12-26 20:49:34      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:

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条

标签:

原文地址:http://www.cnblogs.com/littleYellowDoggy/p/5078711.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!