Class AnimationPerformer
The base class for all animation performers.
Namespace : SpriteAnimations
Fields
_animator
The SpriteAnimator related to that performer
protected SpriteAnimator _animator
Field Value
_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
_currentCycle
List of frames used by the current cycle
protected Cycle _currentCycle
Field Value
_currentCycleElapsedTime
Used when running an animation
protected float _currentCycleElapsedTime
Field Value
_currentFrame
Current frame of the current cycle
protected Frame _currentFrame
Field Value
_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
_onEndAction
protected UnityAction _onEndAction
Field Value
- UnityAction
Properties
Animator
public SpriteAnimator Animator { get; set; }
Property Value
CurrentCycle
Current cycle being played
public Cycle CurrentCycle { get; }
Property Value
CurrentFrame
The current frame displayed in the animator's SpriteRenderer
public Frame CurrentFrame { get; }
Property Value
HasCurrentAnimation
protected bool HasCurrentAnimation { get; }
Property Value
HasCurrentCycle
protected bool HasCurrentCycle { get; }
Property Value
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
floatThe time that has elapsed since the animation started.
amountOfFrames
intThe total number of frames in the animation.
duration
floatThe 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
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
UnityActionThe 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
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
Returns
- AnimationPerformer
The updated PerformerSingle instance.
StartAnimation(SpriteAnimation)
Starts the given sprite animation.
public virtual void StartAnimation(SpriteAnimation animation)
Parameters
animation
SpriteAnimationThe 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
floatThe 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