2017-09-02 50 views
1

我正在尝试为多个assetbundle创建一个下载进度条。所有资产包的总大小通过添加webRequest.GetResponseHeader("Content-Length")来计算。但www.downloadProgress只返回从0到1的值。在单个进度条中下载多个unity3d assetbundle?

这里的示例代码:

float progress = 0; 

for (int i = 0; i < assetToDownload.Count; i++) 
{ 
    UnityWebRequest www = UnityWebRequest.GetAssetBundle(assetToDownload[i], 0, 0); 
    www.Send(); 

    while (!www.isDone) 
    { 
     progress += www.downloadProgress * 100; 
     Debug.Log((progress/totalSize) * 100); 
     yield return null; 

    } 
} 

回答

1

不要用不同势请求获取内容,大小自己做的这么难。您只需要使用统一的0-1值并将它们相加即可。从进度条查看时,这并不会产生差异,并且在执行a **时不会产生这样的痛苦。 我希望这可以帮助。

//To calculate the percantage 
float maxProgress = assetToDownload.Count; 

for (int i = 0; i < assetToDownload.Count; i++) 
{ 
    UnityWebRequest www = UnityWebRequest.GetAssetBundle(assetToDownload[i], 0, 0); 
    www.Send(); 

    //To remember the last progress 
    float lastProgress = progress; 
    while (!www.isDone) 
    { 
     //Calculate the current progress 
     progress = lastProgress + www.downloadProgress; 
     //Get a percentage 
     float progressPercentage = (progress/maxProgress) * 100; 
    } 
}