I'm trying to make a single download progress bar for multiple assetbundle. The total size of all the assetbundle was computed by adding its webRequest.GetResponseHeader("Content-Length")
. But the www.downloadProgress
returns a value from 0 to 1 only.
Here's the sample code:
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;
}
}
Do not make it yourself so hard by getting the content-size with a diffrent request. You just need to use the 0-1 values from unity and add them together. This won't make a diffrence when viewing it from a progressbar and isn't such a pain in the a** to implement. I hope this helps.