2017-09-02 49 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; 
    } 
}