-
Notifications
You must be signed in to change notification settings - Fork 0
Creating Your Custom Transition
To get the full potential of UniSwitcher, definitely create a transition effect!
The transition effect for UniSwitcher must check all the following boxes.
- Must be able to handle all four states defined in
TransitionState. - Is a Canvas GameObject with a script (at the root) that implements
ITransitionBackgroundController. - Is a prefab.
- Is referenced from the
UniSwitcherInstaller.
In UniSwitcher, the Transition is defined in four states, which is defined in the TransitionState enum.
| State Name | Description |
|---|---|
| Ready | The Transition is not started, i.e., ready for deployment. This one is the default state. |
| In | This is where the previous scene is getting covered with the transition screen. |
| Wait | The user only sees the transition screen. |
| Out | This is where the next scene starts to appear below the transition screen. |
(This diagram is here until GitHub Wiki supports mermaid notations)
flowchart TD
A[Ready] -->|"Transition Triggered by PerformSceneTransition()"| B[In]
B -->|""Transition in" animation finished"| C[Wait]
C -->|"IsTransitionAllowed() && Scene Entrypoint finishes running"| D[Out]
D -->|""Transition out" animation finished"| A
The transition effect must be able to handle those states correctly.
For example, you could have an Animator with the four states above as its Animator state.
Your transition effect must have a script that implements this interface (and extends MonoBehaviour.)
For an example implementation, check out Assets/Plugins/UniSwitcher/Sample/TransitionBackgroundController.cs.
When a new Scene is loaded (non-additively.)
If your Canvas is using Screen space - Camera mode, you need to poll the current Camera.main and
update the canvas camera to that one.
Otherwise, you can leave this method as a no-op.
// Your IDE may warn that this is expensive - you may safely suppress the warning because it's only called once per scene change.
var mainCamera = Camera.main;
if (mainCamera != null)
{
mainCanvas.worldCamera = mainCamera;
return;
}
Debug.LogWarning("No main camera found for transition object. It might work weirdly");When the Transition In is needed.
Put the Transition into the "In" state by, e.g., calling SetTrigger on the Animator.
When the Transition Out is needed.
Put the Transition into the "Out" state.
- When the
Switchertries to start a scene change. - When the
Switchertries to load the next scene.
This one is super important! This method tells UniSwitcher if it is okay to trigger the following transition effects.
Usually, it is enough that you check if the transition state is Ready or Wait.
return GetTransitionState() == TransitionState.Ready || GetTransitionState() == TransitionState.Wait;- Used for
IsTransitionAllowed().
Report the current transition state as TransitionState enum.
This probably requires polling your Animator, such as:
var stateHash = transitionAnimator.GetCurrentAnimatorStateInfo(0).fullPathHash;
if (stateHash == Animator.StringToHash("Base Layer.TransitionIn")) {
return TransitionState.In;
} else if ( // and so onCalled for a rare case where you want to force the transition state to the Wait state.
[TIP]
You could create a transition in your Animator to handle this case, but this is only called whenSwitcher.ForceTransitionWait. If you are not using that, you can implement this method as a no-op.