【Unity3D自学记录】获取WWW下载的进度

首先创建一个WWWObj的类

using UnityEngine;
using System.Collections;
public class WWWOBJ : MonoBehaviour {
    private WWW www;
    public string LoadPro;

    public WWWOBJ(string url)
    {
        www = new WWW(url);
    }
    public IEnumerator Load()
    {
        while (!www.isDone)
        {
            LoadPro = (((int)(www.progress * 100)) % 100) + "%";
            Debug.Log("进度:" + LoadPro);
            yield return 1;
        }
        if (www.error != null)
        {
            Debug.Log("Loading error:" + www.url + "\n" + www.error);
        }
        else
        {
            LoadPro = "100%";
            AssetBundle bundle = www.assetBundle;
        }
    }
}



接下来我们就直接调用这个类中的方法就可以了

创建一个脚本

using UnityEngine;
using System.Collections;
public class WWWOBJ : MonoBehaviour {
      IEnumerator Start ()
    {
        WWWOBJ obj = new WWWOBJ("地址URL");
        yield return StartCoroutine(obj.Load());
    }
}

运行以后就会看见Debug出下载的进度。

猜你喜欢

转载自blog.csdn.net/hackdjh/article/details/20454227