-
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!
UniSwitcher uses the following enum and interface to control the transition.
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., waiting. This is the default state. Also reaches this state when the "Out" state ends. |
| In | Requires an explicit interaction to switch to this state. This is where the previous scene is starting to get covered with the transition screen. |
| Wait | When the "In" state ends, the transition state automatically switches to this state. Only the transition screen can be seen by the user. |
| Out | Requires an explicit interaction to switch to this state. This is where the next scene is starting to appear below the transition screen. |
The transition effect must be able to handle those states correctly.
For example, you could have an Animator which has the four states above as its Animator state.
Your transition effect must have a script that implements this interface (and also extends MonoBehaviour.)
For an example implementation, check out Assets/Plugins/UniSwitcher/Sample/TransitionBackgroundController.cs.
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.
var mainCamera = Camera.main;
if (mainCamera != null)
{
mainCanvas.worldCamera = mainCamera;
return;
}
Debug.LogWarning("No main camera found for transition object. It might work in a weird way");Called when the Transition In is needed. Put the transition into the "In" state by e.g., calling SetTrigger on the Animator.
Called when the Transition Out is needed, Put the transition into the "Out" state.
This one is super important! This method tells UniSwitcher if it is okay to trigger the next transition effects.
Usually, it is enough that you check if the transition state is Ready or Wait.
return GetTransitionState() == TransitionState.Ready || GetTransitionState() == TransitionState.Wait;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 Wait state.
[TIP]
You could create a transition in your Animator so that you can 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.