问题描述
(对不起,英语不好) 嗨,我正在使用此代码通过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等),每个文件的值都会跳到结尾!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)