Logo

Tween Animator

Build named animation states and play them from events or code

Overview

Tween Animator plays named states, each with its own sequence of clips. Use it for entrance animations, hover feedback, selection states, or any animation you want to author in the Inspector.

Add it through Add Component -> Evo -> Tween -> Tween Animator. Only one Tween Animator can be attached to a GameObject; put related animations in separate states.


States

Use the state selector at the top of the Inspector to choose a state, and the + button to add one. The state menu lets you duplicate, reorder, delete, or Set as Default.

Give every state a unique State ID. IDs are case-sensitive: Show and show are different. Duplicate IDs resolve to the first matching state.

Each state owns a Tween Sequence. Select the state before adding clips or opening the Timeline Window.

Triggers

TriggerUse it for
ManualPlay the state from a script or a UnityEvent.
Pointer EventReact to Enter, Exit, Down, Up, Click, Select, Deselect, Submit, or Cancel events.
InteractionFollow an Evo UI component's Normal, Highlighted, Pressed, Selected, or Disabled state.

Pointer Event can listen for multiple events. Mouse Button filters Down, Up, and Click; the other events don't use that filter. UI pointer events need an EventSystem, the appropriate input module, and a raycastable UI target. Selection and submit events also require the object to receive those EventSystem events.

For Interaction, assign an Interaction Source that implements IStylerInteractable, such as an Evo UI Button. See Evo UI.

If more than one state matches an automatic event, the first match in the state list wins. Restart On Trigger decides whether triggering the current state starts it again. Direct calls to Play() always restart the requested state.

Playback Settings

SettingBehavior
Play On EnablePlays the default state whenever the component is enabled. This setting applies to the whole component.
Restore On StopRestores the values captured for the current run when it is stopped or disabled.
Playback SpeedMultiplies playback speed. 1 is normal; 0 holds the current time.
Update PhaseAdvances the state in Update, Late Update, or Fixed Update.
LoopPlays once, restarts the whole sequence, or alternates direction with Yoyo.
IterationsTotal sequence iterations when looping. 0 loops forever. A Yoyo forward pass and return pass count as two iterations.

The sequence's Time Mode chooses scaled or unscaled time. Use Unscaled for menus that should animate while Time.timeScale is zero.

Switching states

Changing states preserves the values currently on screen. Clips with From Current enabled can continue smoothly from that point. Normal completion also leaves the final result in place; Restore On Stop is not an automatic reset after completion.


Public API

Use TweenAnimator in the Evo.Tween namespace.

Properties

NameDescription
StatesRead-only view of the state list.
DefaultStateIndex, ActiveStateIndexDefault and active state indices; the active index is -1 before a state is selected for playback.
ActiveState, SequenceActive state and current sequence. Before playback, Sequence uses the default state.
State, IsPlaying, IsPausedCurrent playback status.
Duration, CurrentTime, NormalizedTimeSequence duration, time in seconds, and progress through the current iteration.
HasCapturedValuesWhether there is captured target state available to sample or restore.

Methods

MethodDescription
Play()Restarts the default state.
Play(string id) / Play(int index)Restarts the requested state.
Trigger(string id) / Trigger(int index)Selects a state while respecting Restart On Trigger.
Restart()Restarts the active state, or the default before the first run.
Pause(), Resume(), TogglePause()Controls playback. Toggle starts the state if it is stopped or completed.
Stop() / Stop(bool restore)Stops using the state's restore setting, or an explicit override.
Complete()Jumps to where playback would finish and completes active or paused playback. After an even number of Yoyo iterations, that is the start.
Capture(), Sample(float time), Restore()Captures values, samples an absolute time, and restores captured values.
PrepareStates()Rebuilds all prepared state data. Stops current playback; call after changing state definitions at runtime.
RefreshState(int index)Rebuilds one state; active playback keeps its normalized position.
RebindTriggers()Reconnects triggers after changing their configuration or the interaction source.
GetState(int index), GetStateIndex(string id)Looks up a state; an unknown ID returns -1.

Play requires Play Mode and an active, enabled component. Use the editor preview controls to test animations outside Play Mode.

Events

Started, Paused, Resumed, Stopped, and Completed are C# events with the animator as their argument. Updated receives the animator and normalized progress. Subscribe from code, and unsubscribe when your listener is disabled or disposed.

You can also connect another component's UnityEvent to public methods such as Play(string) or Trigger(string) and supply the state ID in the Inspector.

Example

Create Show and Hide states in the Inspector, then call these methods from your UI events:

PanelAnimation.cs
using UnityEngine;
using Evo.Tween;

public class PanelAnimation : MonoBehaviour
{
    [SerializeField] private TweenAnimator animator;

    public void Show() => animator.Play("Show");
    public void Hide() => animator.Play("Hide");
    public void Pause() => animator.Pause();
    public void Resume() => animator.Resume();
}

On this page