Search Unity

It appears AsyncOperationHandle.PercentComplete is 0 or 1 for loading scenes

Discussion in 'Addressables' started by bfloyd, Jul 22, 2019.

  1. bfloyd

    bfloyd

    Joined:
    Dec 6, 2017
    Posts:
    9
    It appears AsyncOperationHandle.PercentComplete is 0 or 1 for loading scenes (even the downloaded asset bundles). Is this by design?

    I originally added code snippets, but the forum kept complaining that it appears to be a spam post which was really not helpful.
     
  2. bfloyd

    bfloyd

    Joined:
    Dec 6, 2017
    Posts:
    9
    lol lame forum rules. I'll repost the rest here ...

    example

    Code (CSharp):
    1.  
    2.  
    3.  
    4.  
    5. [ExecuteInEditMode]
    6.  
    7. public class ProgressBar : MonoBehaviour
    8.  
    9. {
    10.  
    11.     ...
    12.  
    13.  
    14.  
    15.     public IEnumerator FillUntilDone<T>(AsyncOperationHandle<T> operation, float startingFillProportion,
    16.  
    17.         float endingFillProportion)
    18.  
    19.     {
    20.  
    21.         var previousFillProportion = startingFillProportion;
    22.  
    23.         var isDone = false;
    24.  
    25.         while (!isDone)
    26.  
    27.         {
    28.  
    29.             if (operation.IsDone)
    30.  
    31.             {
    32.  
    33.                 isDone = true;
    34.  
    35.             }
    36.  
    37.             else
    38.  
    39.             {
    40.  
    41.                 var fillProportion = Mathf.Lerp(startingFillProportion, endingFillProportion, operation.PercentComplete);
    42.  
    43.                 fillProportion = Mathf.Max(previousFillProportion, fillProportion); // Progress can only increase.
    44.  
    45.                 SetProgress(fillProportion);
    46.  
    47.                 previousFillProportion = fillProportion;
    48.  
    49.             }
    50.  
    51.  
    52.  
    53.             yield return null;
    54.  
    55.         }
    56.  
    57.     }
    58.  
    59. }
    60.  
    61.  


    Here is an example of how it's used

    Code (CSharp):
    1.        
    2.  
    3.  ...
    4.  
    5. var async = Addressables.LoadSceneAsync("Scenes/Test.unity", UnityEngine.SceneManagement.LoadSceneMode.Single, false);
    6.  
    7.  
    8.  
    9.         yield return ProgressBar.FillUntilDone(async, _maxLoadingBarProgress,
    10.  
    11.             ProgressBar.AssetBundleDownloadToInstallRatio);
    12.  
    13.  
    14.  
    15.         async.Result.Activate();
    16.  
    17.  
     
  3. CharBodman

    CharBodman

    Joined:
    Sep 20, 2018
    Posts:
    36
    It's a bug.

    Been this way since 0.7.4

    It's apparently fixed in an upcoming update.
     
  4. bfloyd

    bfloyd

    Joined:
    Dec 6, 2017
    Posts:
    9
    sounds great. thanks