非同期ローディング


引用: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;
        }
    }

}