Skip to content

Display Progress Bar

Collapsed Plug edited this page Nov 30, 2021 · 2 revisions

UniSwitcher has a feature to report scene loading progress. It is done via the ProgressDisplayController class.

What the Progress Bar for Uniswitcher looks like

The progress bar for UniSwitcher must check all the following boxes:


  • Is a GameObject that has the implementation of ProgressDisplayController as its component.
  • Is placed in the Scene that you want to show it.
  • Is referenced from the Switcher component in the scene from sceneProgressBarController property.

The progress bar will show up only if the originating Scene has one.
i.e., If you want to show a progress bar on the scene transition from A to B, the progress bar must exist on Scene A.

⚠️ It will not work if put in a global, DontDestroyOnLoad context GameObject.

ProgressDisplayController

You can also call the methods yourself to repurpose the progress bar to show other progress.

SetProgress(float progress)

When is it called?

When the loading progress changes.

What should I do here?

You probably want to set the parameter progress as, e.g., Image's fillAmount.

Enable(bool reset = true)

When is it called?

When the progress bar is needed.

What should I do here?

Display the progress bar if it's hidden. You may use Animation to do it.
If reset is true, directly set the displayed progress to zero.

Disable()

When is it called?

When the progress bar is not needed anymore.

What should I do here?

Hide the progress bar if it's shown. You may use Animation to do it.

⚠️ [NOTE!]
Do not destroy the progress bar instance here! This method is meant to merely hide the progress bar from view. Destroying the progress bar is done in a separate method.

SetDDoL()

When is it called?

When the Scene load is complete.

What should I do here?

Set the progress bar as DontDestroyOnLoad() in this method.

Why?

This method is required as some progress bar may want to show 100% after the scene loads;
but attempts to do that without DDoL will fail because the Scene would have changed by the time 100% is displayed, and the progress bar that was on the original Scene is destroyed (which will crash the game; we call this the phantom 100%.)
This method makes sure that the progress bar in the original Scene lives after the scene change to make sure 100% can be seen.

Close()

When is it called?

When the scene change is complete.

What should I do here?

You must implement this method as an async method, and you must destroy the ProgressBar GameObject here.

Why?

This method is used in conjunction with SetDDoL(). Due to the phantom 100%, the progress bar is in the DDoL state after the scene load. Switcher will call Close() along with SetDDoL() so that the progress bar is correctly cleaned up.
Since this method is an async method, you can cause the bar to disappear after an animation.

public override async UniTask Close() {
    animator.SetTrigger("FadeOut"); // A hyphothetical animation that takes a second to complete
    await UniTask.Delay(TimeSpan.FromSeconds(1f));
    Destroy(gameObject);
}

Clone this wiki locally