GooglePlayInstant/LoadingScreen/LoadingBar.cs
/// <summary>
/// Updates a loading bar by the progress made by an asynchronous operation up to a specific percentage of
/// the loading bar. 
/// </summary>
Updates a loading bar by the progress made by an asynchronous operation up to a specific percentage of
the loading bar.
Updates a loading bar by the progress made by an asynchronous operation up to a specific percentage of the loading bar .
public static IEnumerator Update(AsyncOperation operation, float percentageOfLoadingBar)
        {
            var loadingBarRectTransform = GameObject.Find(LoadingBarGameObjectName).GetComponent<RectTransform>();
            var loadingBarFillRectTransform =
                GameObject.Find(LoadingBarFillGameObjectName).GetComponent<RectTransform>();
            var loadingBarFillMaxWidth = loadingBarRectTransform.sizeDelta.x - LoadingBarFillPadding;
            var loadingMaxWidth = loadingBarFillMaxWidth * percentageOfLoadingBar;
            var currentLoadingBarFill = loadingBarFillRectTransform.sizeDelta.x;
            var loadingIsDone = false;
            while (!loadingIsDone)
            {
                loadingBarFillRectTransform.sizeDelta = new Vector2(
                    currentLoadingBarFill + loadingMaxWidth * operation.progress,
                    loadingBarFillRectTransform.sizeDelta.y);
                loadingBarFillRectTransform.position = new Vector2(
                    loadingBarRectTransform.position.x -
                    (loadingBarFillMaxWidth - loadingBarFillRectTransform.sizeDelta.x) / 2f,
                    loadingBarFillRectTransform.position.y);
                if (operation.isDone)
                {
                    loadingIsDone = true;
                }
                yield return null;
            }
        }
public static IEnumerator Update ( AsyncOperation operation , float percentageOfLoadingBar ) { var loadingBarRectTransform = GameObject . Find ( LoadingBarGameObjectName ) . GetComponent < RectTransform > ( ) ; var loadingBarFillRectTransform = GameObject . Find ( LoadingBarFillGameObjectName ) . GetComponent < RectTransform > ( ) ; var loadingBarFillMaxWidth = loadingBarRectTransform . sizeDelta . x - LoadingBarFillPadding ; var loadingMaxWidth = loadingBarFillMaxWidth * percentageOfLoadingBar ; var currentLoadingBarFill = loadingBarFillRectTransform . sizeDelta . x ; var loadingIsDone = false ; while ( ! loadingIsDone ) { loadingBarFillRectTransform . sizeDelta = new Vector2 ( currentLoadingBarFill + loadingMaxWidth * operation . progress , loadingBarFillRectTransform . sizeDelta . y ) ; loadingBarFillRectTransform . position = new Vector2 ( loadingBarRectTransform . position . x - ( loadingBarFillMaxWidth - loadingBarFillRectTransform . sizeDelta . x ) / 2f , loadingBarFillRectTransform . position . y ) ; if ( operation . isDone ) { loadingIsDone = true ; } yield return null ; } }
Updates a loading bar by the progress made by an asynchronous operation up to a specific percentage of
the loading bar.
Updates a loading bar by the progress made by an asynchronous operation up to a specific percentage of the loading bar .
// Total amount of space the loading bar can occupy // Percentage of space that is allocated for this async operation // Current width of the loading bar // Changing the width of the rectangle makes it shorter (or larger) on both sides--thus requiring // the rectangle's x position to be moved left by half the amount it's been shortened.
operation
AsyncOperation
percentageOfLoadingBar
float