Question:
I want to get the size of assetBundle before finishing download the file. And I can show the remaining time to user. In Unity2018.2 , can we get the file size or downloaded file size that let me multiply by progress? Or there is other ways to calculate the remaining time?
I know WWW.responseHeaders contain the information, but it seems need to finish downloading.
Here is my code currently.
using (WWW downloadPackageWWW = new WWW(pkg.url))
{
while (!downloadPackageWWW.isDone)
{
print("progress: " + downloadPackageWWW.progress * 100 + "%");
yield return null;
}
if (downloadPackageWWW.error != null)
print("WWW download had an error:" + downloadPackageWWW.error);
if (downloadPackageWWW.responseHeaders.Count > 0)
print(pkg.fileName + ": " + downloadPackageWWW.responseHeaders["Content-Length"]+" byte");
byte[] bytes = downloadPackageWWW.bytes;
File.WriteAllBytes(pkgPath, bytes);
}
--
Update:
To get the remaining time, I come up a ideal that calculate by Time.deltaTime, and we don't need to know the total file size and download speed.
float lastProgress = 0;
while (!www.isDone)
{
float deltaProgress = www.progress - lastProgress;
float progressPerSec = deltaProgress / Time.deltaTime;
float remaingTime = (1 - www.progress) / progressPerSec;
print("Remaining: " + remaingTime + " sec");
lastProgress = www.progress;
yield return null;
}