-
Notifications
You must be signed in to change notification settings - Fork 0
Display Progress Bar
UniSwitcher has a feature to report scene loading progress. It is done via the ProgressDisplayController class.
The progress bar for UniSwitcher must check all the following boxes:
- Is a GameObject that has the implementation of
ProgressDisplayControlleras its component. - Is placed in the scene that you want to show it.
- Is referenced from the
Switchercomponent in the scene fromsceneProgressBarControllerproperty.
The progress bar will show up if the originating scene has one.
If you want to show a progress bar on the scene transition from A to B, the progress bar must exist on scene A and
check all the boxes above.
It will not work if put in a global, DontDestroyOnLoad context GameObject.
You can also call the methods yourself to repurpose the progress bar to show other progress.
Switcher will send the scene loading progress to this method.
You probably want to set the parameter progress to e.g., Image's fillAmount.
Called when the progress bar is needed.
If reset is true, directly set the displayed progress to zero.
Called when the progress bar is not needed anymore.
[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.
Called when the scene load is complete. Set the progress bar as DontDestroyOnLoad() in this method.
This 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 by the time 100% is shown,
the scene would have changed, and the progress bar that was on the original scene is
destroyed (which will crash the game; we call this the phantom 100%.)
This makes sure that the progress bar in the original scene lives after the scene change
just to make sure 100% can be seen.
Called when the scene change is complete. You must implement this method as an async method,
and you must destroy the ProgressBar GameObject here.
This 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);
}