Class SpriteAnimator
The Sprite Animator. Responsible for playing animations by changing the sprites of a SpriteRenderer based on the fps of the playing animation.
Namespace : SpriteAnimations
Fields
_animationChanged
[Tooltip("The event that will be invoked when the animation changes.")]
[SerializeField]
protected UnityEvent<SpriteAnimation> _animationChangedField Value
- UnityEvent<SpriteAnimation>
_animations
protected Dictionary<string, SpriteAnimation> _animationsField Value
_currentAnimation
protected SpriteAnimation _currentAnimationField Value
_currentPerformer
protected AnimationPerformer _currentPerformerField Value
_defaultAnimation
[Tooltip("The animation that will be played when this animator behaviour starts.")]
[SerializeField]
protected SpriteAnimation _defaultAnimationField Value
_loaded
protected bool _loadedField Value
_performersFactory
protected PerformerFactory _performersFactoryField Value
_playOnStart
[Tooltip("If the animator should start playing on start.")]
[SerializeField]
protected bool _playOnStartField Value
_spriteAnimations
[Tooltip("The animations that can be played by this Sprite Animator. Use the Animations Manager to edit this.")]
[SerializeField]
protected List<SpriteAnimation> _spriteAnimationsField Value
_spriteRenderer
[Tooltip("The sprite renderer used for the animation.")]
[SerializeField]
protected SpriteRenderer _spriteRendererField Value
- SpriteRenderer
_state
protected AnimatorState _stateField Value
_stateChanged
[Tooltip("The event that will be invoked when the animator state changes.")]
[SerializeField]
protected UnityEvent<AnimatorState> _stateChangedField Value
- UnityEvent<AnimatorState>
_updateMode
[Tooltip("The update mode of the animator.")]
[SerializeField]
protected UpdateMode _updateModeField Value
Properties
AnimationChanged
The event that will be invoked when the animation changes.
public UnityEvent<SpriteAnimation> AnimationChanged { get; }Property Value
- UnityEvent<SpriteAnimation>
Animations
protected Dictionary<string, SpriteAnimation> Animations { get; }Property Value
AnimationsList
The list of animations registered to this animator.
Important: Changing this at runtime will have no effect on the capacity of the animator to play changed list of animations.
public List<SpriteAnimation> AnimationsList { get; }Property Value
CurrentAnimation
The current animation being played by the animator.
public SpriteAnimation CurrentAnimation { get; }Property Value
DefaultAnimation
The default animation that will be played when this animator behaviour starts.
public SpriteAnimation DefaultAnimation { get; }Property Value
IsPaused
Is The animator paused?
public bool IsPaused { get; }Property Value
IsPlaying
Is the animator playing?
public bool IsPlaying { get; }Property Value
IsStopped
Is The animation stopped?
public bool IsStopped { get; }Property Value
SpriteRenderer
The sprite renderer used by the animator.
public SpriteRenderer SpriteRenderer { get; }Property Value
- SpriteRenderer
State
The current state of the animator.
public AnimatorState State { get; }Property Value
StateChanged
The event that will be invoked when the animator state changes.
public UnityEvent<AnimatorState> StateChanged { get; }Property Value
- UnityEvent<AnimatorState>
Methods
Awake()
protected virtual void Awake()CalculateCurrentAnimationDuration()
Calculates the duration of the current animation. Depending on the type of animation this can have serious perfomance impacts as it has to evaluate all frames of all the animation cycles.
public float CalculateCurrentAnimationDuration()Returns
- float
- The duration of the current animation. 
ChangeAnimation(SpriteAnimation)
This changes the current animation to be played by the animator. It will call the current animation Stop() method and the new animation Start() method.
protected void ChangeAnimation(SpriteAnimation animation)Parameters
- animationSpriteAnimation
FixedUpdate()
protected virtual void FixedUpdate()GetAnimationByName(string)
Gets a registered animation by its name
public SpriteAnimation GetAnimationByName(string name)Parameters
- namestring
Returns
- SpriteAnimation
- The animation or null if not found 
LateUpdate()
protected virtual void LateUpdate()LoadAnimator()
protected void LoadAnimator()Pause()
Pauses the animator. Use Resume to continue.
public AnimationPerformer Pause()Returns
Play()
Plays the default animation. Or the first animation registered to the animator if there is no default animation registered.
public AnimationPerformer Play()Returns
Play(SpriteAnimation)
Plays the given sprite animation.
public AnimationPerformer Play(SpriteAnimation animation)Parameters
- animationSpriteAnimation
- The animation to play. 
Returns
- AnimationPerformer
- The animation performer. 
Play(string)
Plays the specified animation by its name. Note that the animation must be registered to the animator in order to be found.
public AnimationPerformer Play(string name)Parameters
- namestring
- The name of the animation. 
Returns
- AnimationPerformer
- The AnimationPerformer instance for the played animation, or null if the animation is not found. 
Play<TAnimator>(SpriteAnimation)
Plays the specified animation.
public TAnimator Play<TAnimator>(SpriteAnimation animation) where TAnimator : AnimationPerformerParameters
- animationSpriteAnimation
- The animation to play. 
Returns
- TAnimator
- The animation performer. 
Type Parameters
- TAnimator
- The type of the animation performer. 
Play<TAnimator>(string)
Plays the specified animation by its name. Note that the animation must be registered to the animator in order to be found.
public TAnimator Play<TAnimator>(string name) where TAnimator : AnimationPerformerParameters
- namestring
- The name of the animation to play. 
Returns
- TAnimator
- The AnimationPerformer instance for the played animation, or null if the animation is not found. 
Type Parameters
- TAnimator
- The type of the animator. 
Resume()
Resumes a paused animator.
public AnimationPerformer Resume()Returns
Start()
protected virtual void Start()Stop()
Stops animating
public void Stop()TryGetAnimationByName(string, out SpriteAnimation)
Tries to get a registered animation by its name
public bool TryGetAnimationByName(string name, out SpriteAnimation animation)Parameters
- namestring
- animationSpriteAnimation
Returns
- bool
- True if the animation is found, false otherwise 
Update()
protected virtual void Update()