Get size of an online assetbundle and progress in Kb ?

Hi everyone,

I’ve a script for downloading assetbundle that works fine but I’d like to show the progress in term of size (Kb).

I use this code:

WWW download = WWW.LoadFromCacheOrDownload(assetURL, m_Version)
 myProgressBar.Progress = download.Progress;

And I show this:  (myProgressBar.Progress * 100) + "%";

That’s fine but if I want to show the size (and not the %) from the “download” object by using download.Size.
But I’ve got this error when I use it:

WWWCached data can only be accessed using the assetBundle property!
UnityEngine.WWW:get_size()

So I’ve tried another way that cause the same error :frowning:

    WWW download = WWW.LoadFromCacheOrDownload(assetURL, m_Version)
     while (!download.isDone)
    {
        progressBar.Progress = (int)(download.bytesDownloaded / 1000);
        progressBar.AssetSize = (int)((1 / download.progress) * progressBar.Progress);
    }

I didn’t understand how you can’t have the size and the downloaded size if you have the progress property… Progress is normaly the Size divided by the bytesDownloaded , no ?!

Has someone found a solution ?

I finally found an answer:

                    //Get size of the asset
                    WebRequest req = HttpWebRequest.Create(assetURL);
                    req.Method = "HEAD";
                    float ContentLength;
                    using (System.Net.WebResponse resp = req.GetResponse())
                    {
                        float.TryParse(resp.ContentLength.ToString(), out ContentLength);
                    }

                    while (!download.isDone)
                    {
                        if (progressBar != null)
                        {
                            progressBar.LabelInformations = "Downloading Assets";
                            progressBar.Progress = download.progress;
                            progressBar.AssetSize = ContentLength / 1000000; //(Mb)
                        }
                        yield return null;
                    }

Case closed.