Extra WWW download statistics?

My game loads AssetBundles off the internet while players watch a % climb from 0 to 100, which is rather boring. I am working on a more elegant loading interface, and it would be quite cool if I could show players (at a minimum) how many MB they have downloaded, and how many MB are left to download.

I know most webservers provide the total size of a file in the initial http request response, but is there any way to get this information through Unity’s WWW object? Accessing www.size before the download is complete results in a runtime error. “You are trying to load data from a www stream which has not completed the download yet.”

Check out responseheaders! HTTP Response Headers? - Questions & Answers - Unity Discussions

It’s pretty simple to implement a naming system that would work; just add the size into the file name. I wrote a script for doing that. You can have as many underscores in the name as you want, just the size has to be after the last. I used ASSET_BUNDLE_24.1.unity3d as a tester for this.

var assetBundleExtension : String; //The extension, minus the '.' , so unity3d for .unity3d

function Start() {
	assetBundleExtension = "." + assetBundleExtension;
	DownloadAssetBundle("http://full/url/to/bundle_size.unity3d");
}

function DownloadAssetBundle (url : String) {
	var fileNameWithExt = Path.GetFileName(url);
	var fileName = fileNameWithExt.Replace(assetBundleExtension, "");
	fileName = fileName.Substring(0, fileName.LastIndexOf('_'));
	var fileSize = (fileNameWithExt.Replace(fileName + "_", "")).Replace(assetBundleExtension, "");
	print("Downloading asset bundle: " + fileName + ", size: " + fileSize + "MB.");
}

Throw that in a new UnityScript file and check it out. Just call on the DownloadAssetBundle() function with the url in the parenthesis, and it will decipher all of it for you. Then, you can access fileSize, so if it’s at, say, 8%, you could do

var currentSize = .08 * fileSize;

That should do it! I didn’t test multiplying it by a percent, you may have to parseint on it, if so just google it. Real simple.