Using A Transition Animator

Create An Instance

To use a transition animator, begin by creating an instance of it. All available transition animators are listed in Unity's Create menu, accessed by either right-clicking in the Project window or selecting Assets in the menu bar.

The available transition animators are listed in the Create menu.



This will create a new transition animator asset in your project. Select the new transition animator instance to open the inspector and view its properties. Here you can adjust any exposed properties on the transition animator, allowing you to tweak each transition animator on a per instance basis. For example, the Fade To Color animator exposes the following properties:

The 'Fade To Color' transition animator inspector.



You can have many instances of the same transition animator in your project, each configured differently. For example, you might have two instances of the 'Fade To Color' animator, one that fades to black, and one that fades to white.

Using With Storyboards

To use this new transition animator instance in a storyboard transition, simply select the transition in the storyboard, and drop the instance onto the Custom Animator field, as shown in the video below. This transition will now be animated by the specified instance.

Setting a transition animator on a storyboard transition.


Using Directly With Canvas Controllers

To use a transition animator instance when presenting and dismissing canvas controllers from script, you must provide, or vend, the animator instance to Canvas Flow when the transition is about to be performed. This process is as follows:

When a transition is to be performed, the target canvas controller's1 transitioningAnimatorVendor will be asked to provide an animator for the transition. You should therefore specify the target canvas controller's transitioningAnimatorVendor and return your animator instance in the TransitioningAnimatorForContext method.

1. The target canvas controller is the canvas controller being acted upon - i.e. the canvas controler being presented or being dismissed. Therefore, in a presentation, this will be the transition context's destinationCanvasController, whereas in a dismissal, this will be the transition context's sourceCanvasController.

For example, in Canvas Flow's Transitions example, the menu screen sets itself as the transitioningAnimatorVendor when presenting a canvas controller. This is done in the configuration action, as shown below.

PresentCanvasController<TEFadeTransitionCanvasController>(
    configuration: (fadeDescriptionCanvasController) =>
{
    fadeDescriptionCanvasController.transitioningAnimatorVendor = this;
});

Then the menu screen implements the required TransitioningAnimatorForContext method, returning the appropriate transition animator based upon the context.

// Set in the inspector.
public CanvasControllerTransitioningAnimator fadeTransitionAnimator;

public ICanvasControllerTransitioningAnimator TransitioningAnimatorForContext(
    CanvasControllerTransitionContext transitionContext)
{
    // The presented canvas controller is the destination on downstream transitions (Present)
    // and the source on upstream transitions (Dismiss).
    CanvasController presentedCanvasController = (transitionContext.isUpstream) ?
        transitionContext.sourceCanvasController : transitionContext.destinationCanvasController;

    if (presentedCanvasController is TEFadeTransitionCanvasController)
    {
      return fadeTransitionAnimator;
    }

    return null
}

You may return null in your TransitioningAnimatorForContext implementation to use the default transition animator. For example, in the above implementation, we only use our fade animator if we are transitioning to or from the TEFadeTransitionCanvasController, otherwise null is returned and the default animator is used.