如何显示Android中任何文件类型的unity UI Slider填充为unitywebrequest downloadProgress?

问题描述

(对不起,英语不好) 嗨,我正在使用此代码通过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;
}

下载任何文件类型的代码时,统一编辑器中的一切都很好,我可以看到滑块值已更改并填充了它:

enter image description here

但是我的导出.apk结果不同,仅当应用程序下载.mp4文件时,它才会显示填充滑块,但是对于其他文件类型(如.xml,.unity3d等),每个文件的值都会跳到结尾!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...