-
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 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,DontDestroyOnLoadcontext GameObject.
You can also call the methods yourself to repurpose the progress bar to show other progress.
When the loading progress changes.
You probably want to set the parameter progress as, e.g., Image's fillAmount.
When the progress bar is needed.
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.
When the progress bar is not needed anymore.
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.
When the Scene load is complete.
Set the progress bar as DontDestroyOnLoad() in this method.
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.
When the scene change is complete.
You must implement this method as an async method, and you must destroy the ProgressBar GameObject here.
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);
}