(抱歉英语不好)嗨,我正在使用此代码通过 unitywebrequest 下载assetbundle 或 .mp4 文件:
public IEnumerator Download (List<string> urls) {
for (int i = 0; i < urls.Count; i++) {
string ext = Path.GetExtension (urls[i]);
if (ext == ".mp4") {
uwr = UnityWebRequest.Get (urls[i]);
}
if(ext == ".unity3d") {
uwr = UnityWebRequestAssetBundle.GetAssetBundle(urls[i]);
}
string fileName = Path.GetFileName (urls[i]);
string path = Path.Combine (myFolder + "/" + fileName);
uwr.downloadHandler = new DownloadHandlerFile (path);
StartCoroutine (ShowDownloadProgress (uwr)); // Progress Bar With Unity Slider
yield return uwr.SendWebRequest ();
if (uwr.isNetworkError || uwr.isHttpError) {
print ("Error");
}
else {
print ("File successfully downloaded and saved to " + path);
}
}
}
并使用此代码通过统一滑块显示下载进度:
public IEnumerator ShowDownloadProgress (UnityWebRequest www) {
while (!www.isDone) {
downloadProgressSlider.value = www.downloadProgress;
downloadProgressTxt.text = (string.Format ("{0:0%}", www.downloadProgress));
yield return new WaitForSeconds (.01f);
}
downloadProgressSlider.value = 0;
}
当代码下载任何文件类型时,统一编辑器中的一切都很好,我可以看到滑块值发生变化并填充它:
但是我的导出 .apk 有不同的结果,它仅在应用程序下载 .mp4 文件时显示填充滑块,但对于 .xml、.unity3d 等其他文件类型,每个文件的值都跳到结尾!