www.progress ??

Hi everyone!

I’m downloading some asset bundles for my game, but i’m having some troubles show the completion of the download.

i’m saving the www.progress into a float, that i later call in my screen to show the progress.

I have two problems with this:

  • Making that progress shown as 0-100% (The progress returns a float between 0 and 1)
  • The progres stays unchanged for realy long times, and then it jumps a wide amount, like it stays at 20% and stays like that for almost 5 minutes, and then jumped to 85%

The old method i used to convert the value was this:
float NewValue = (((AssetBundlesManager.Instance.getDownloadedProgress() - 0) * (100 - 0)) / (1 - 0)) + 0;

This is my method i’m using for downloading the asset bundles

public IEnumerator downloadAssetBundle( string bundleName, int version)
    {
        string keyName = SERVER_URL + bundleName + version.ToString();

        if (_assetBundleRefs.ContainsKey(keyName))
            yield return null;
        else
        {
            using (WWW www = WWW.LoadFromCacheOrDownload(SERVER_URL + bundleName, version))
            {
                //downloaded = request.progress;

                while (!www.isDone)
                {
                    _downloaded = www.progress;
                    yield return null;
                }

                yield return www;

                if (www.error != null)
                    throw new Exception("WWW Download: " + www.error);

                AssetBundleRef abRef = new AssetBundleRef(bundleName, version);
                abRef.assetBundle = www.assetBundle;
                abRef.assetBundle.name = bundleName;
                _assetBundleRefs.Add(keyName, abRef);
            }
        }

Multiply by 100.

–Eric

1 Like

Wow… that was way easier than i tougth.

Thanks!

p/s: i fell kinda stupid rigth now xD

If you want to make it more complicated you could use Lerp. :wink:

var progressPercent = Mathf.Lerp (0, 100, www.progress);

–Eric