unity加载AssetBundle包并显示进度条
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class ABTest : MonoBehaviour {
public Text textProgress;
private void Awake()
{
StartCoroutine(Download());
}
IEnumerator Download()
{
string url = Application.streamingAssetsPath + "/scenes/"+ "test" + ".ab";
AssetBundle ab ;
using (UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url))
{
request.SendWebRequest();
while (!request.isDone)
{
Debug.Log(request.downloadProgress);
yield return null;
}
if (request.isDone)
{
Debug.Log(100);
}
ab = (request.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
if (ab == null)
{
Debug.LogError("AB包为空");
yield break;
}
}
Debug.Log("成功");
yield break;
}
}