Table of Contents

Class AnimationPerformer

The base class for all animation performers.

Namespace : SpriteAnimations

Fields

_animator

The SpriteAnimator related to that performer

protected SpriteAnimator _animator

Field Value

SpriteAnimator

_currentAnimation

The current animation associated with the performer. Note that the performer may have a current animation set but may not be playing it.

protected SpriteAnimation _currentAnimation

Field Value

SpriteAnimation

_currentCycle

List of frames used by the current cycle

protected Cycle _currentCycle

Field Value

Cycle

_currentCycleElapsedTime

Used when running an animation

protected float _currentCycleElapsedTime

Field Value

float

_currentFrame

Current frame of the current cycle

protected Frame _currentFrame

Field Value

Frame

_frameIdActions

protected Dictionary<string, UnityAction<Frame>> _frameIdActions

Field Value

Dictionary<string, UnityAction<Frame>>

_frameIndexActions

protected Dictionary<int, UnityAction<Frame>> _frameIndexActions

Field Value

Dictionary<int, UnityAction<Frame>>

_isPlaying

If the performer is currently playing an animation

protected bool _isPlaying

Field Value

bool

_onEndAction

protected UnityAction _onEndAction

Field Value

UnityAction

Properties

Animator

public SpriteAnimator Animator { get; set; }

Property Value

SpriteAnimator

CurrentCycle

Current cycle being played

public Cycle CurrentCycle { get; }

Property Value

Cycle

CurrentFrame

The current frame displayed in the animator's SpriteRenderer

public Frame CurrentFrame { get; }

Property Value

Frame

HasCurrentAnimation

protected bool HasCurrentAnimation { get; }

Property Value

bool

HasCurrentCycle

protected bool HasCurrentCycle { get; }

Property Value

bool

Methods

CalculateFrameIndex(float, int, float)

Calculates the frame index based on the elapsed time, amount of frames, and duration.

protected int CalculateFrameIndex(float elapsedTime, int amountOfFrames, float duration)

Parameters

elapsedTime float

The time that has elapsed since the animation started.

amountOfFrames int

The total number of frames in the animation.

duration float

The duration of the animation in seconds.

Returns

int

The index of the current frame to display.

ClearFramePlayedListeners()

protected void ClearFramePlayedListeners()

InvokeFramePlayed(int, Frame)

protected void InvokeFramePlayed(int index, Frame frame)

Parameters

index int
frame Frame

SetOnEnd(UnityAction)

Sets the action to be invoked when the animation ends. This overrides previous actions defined for that animation end.

public AnimationPerformer SetOnEnd(UnityAction action)

Parameters

action UnityAction

The UnityAction to be invoked.

Returns

AnimationPerformer

The updated SpriteAnimationPerformer instance.

SetOnFrame(int, UnityAction<Frame>)

Sets an action to be performed when a specific frame index is played.

public AnimationPerformer SetOnFrame(int frameIndex, UnityAction<Frame> action)

Parameters

frameIndex int

The index of the frame.

action UnityAction<Frame>

The action to be performed.

Returns

AnimationPerformer

The SpriteAnimationPerformer instance.

SetOnFrame(string, UnityAction<Frame>)

Sets an action to be invoked when a specific frame ID is played.

public AnimationPerformer SetOnFrame(string id, UnityAction<Frame> action)

Parameters

id string

The frame ID.

action UnityAction<Frame>

The UnityAction to be invoked.

Returns

AnimationPerformer

The updated PerformerSingle instance.

StartAnimation(SpriteAnimation)

Starts the given sprite animation.

public virtual void StartAnimation(SpriteAnimation animation)

Parameters

animation SpriteAnimation

The sprite animation to start.

StopAnimation()

Stops the animation and clears all the frame index actions, frame ID actions, and the on end action.

public virtual void StopAnimation()

Tick(float)

The method called every time the animator should evaluate if the frame must be changed.

public abstract void Tick(float deltaTime)

Parameters

deltaTime float

The time elapsed since the last tick.

ValidateAnimation(SpriteAnimation)

Validates if the animation should be played.

protected bool ValidateAnimation(SpriteAnimation animation)

Parameters

animation SpriteAnimation

Returns

bool

true if animation can be played

Events

FramePlayed

Event invoked when this performer changed the current frame displayed at the animator's SpriteRenderer

public event FramePlayedEvent FramePlayed

Event Type

FramePlayedEvent