Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

www.progress ??

Discussion in 'Scripting' started by CalaveraX, Aug 19, 2014.

  1. CalaveraX

    CalaveraX

    Joined:
    Jul 11, 2013
    Posts:
    143
    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
    Code (CSharp):
    1. public IEnumerator downloadAssetBundle( string bundleName, int version)
    2.     {
    3.         string keyName = SERVER_URL + bundleName + version.ToString();
    4.  
    5.         if (_assetBundleRefs.ContainsKey(keyName))
    6.             yield return null;
    7.         else
    8.         {
    9.             using (WWW www = WWW.LoadFromCacheOrDownload(SERVER_URL + bundleName, version))
    10.             {
    11.                 //downloaded = request.progress;
    12.  
    13.                 while (!www.isDone)
    14.                 {
    15.                     _downloaded = www.progress;
    16.                     yield return null;
    17.                 }
    18.  
    19.                 yield return www;
    20.  
    21.                 if (www.error != null)
    22.                     throw new Exception("WWW Download: " + www.error);
    23.  
    24.                 AssetBundleRef abRef = new AssetBundleRef(bundleName, version);
    25.                 abRef.assetBundle = www.assetBundle;
    26.                 abRef.assetBundle.name = bundleName;
    27.                 _assetBundleRefs.Add(keyName, abRef);
    28.             }
    29.         }
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Multiply by 100.

    --Eric
     
    CalaveraX likes this.
  3. CalaveraX

    CalaveraX

    Joined:
    Jul 11, 2013
    Posts:
    143
    Wow.... that was way easier than i tougth.

    Thanks!

    p/s: i fell kinda stupid rigth now xD
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    If you want to make it more complicated you could use Lerp. ;)

    Code (csharp):
    1. var progressPercent = Mathf.Lerp (0, 100, www.progress);
    --Eric