Skip to main content

Animator Binders

Binders that drive Animator parameters.


Common behaviour

Every Animator binder inherits AnimatorSetParameterBinder<T> and:

  1. Takes the Animator parameter name (ParameterName) in the Inspector
  2. Sets the parameter through Animator.SetBool/SetFloat/SetInt
  3. Checks CanExecute, by default Target.gameObject.activeInHierarchy
  4. Skips the Set call when the current value already matches

Reverse binding (OneWayToSource)

In OneWayToSource the Animator binders hand an Action<T> or IRelayCommand<T> back to the ViewModel, so animations can be triggered from the ViewModel.

Modes: OneWay, OneTime, OneWayToSource (TwoWay is not allowed).


AnimatorSetBoolBinder

Binds Animator.SetBool.

PropertyDescription
ParameterNameName of the bool parameter in the Animator
_converterOptional value converter (for example BoolInvertConverter)
[ViewModel]
public partial class CharacterViewModel
{
[OneWayBind] private bool _isRunning;
// Bind to AnimatorSetBoolBinder with ParameterName = "IsRunning"
}

AnimatorSetFloatBinder

Binds Animator.SetFloat.

PropertyDescription
ParameterNameName of the float parameter in the Animator
ConverterIConverter<float, float> (optional)
[ViewModel]
public partial class CharacterViewModel
{
[OneWayBind] private float _speed;
// Bind to AnimatorSetFloatBinder with ParameterName = "Speed"
}

AnimatorSetIntBinder

Binds Animator.SetInteger.

PropertyDescription
ParameterNameName of the int parameter in the Animator
ConverterIConverter<int, int> (optional)

AnimatorSetTriggerBinder

Binds Animator.SetTrigger. Works differently: OneWayToSource only. Its pair, AnimatorResetTriggerBinder, calls ResetTrigger: a trigger that was set but never consumed otherwise stays active.

Hands an Action or IRelayCommand to the ViewModel for firing the trigger:

[ViewModel]
public partial class CharacterViewModel
{
[OneWayToSourceBind] private IRelayCommand _jumpTrigger;
// or: [OneWayToSourceBind] private Action _jumpTrigger;

public void Jump()
{
_jumpTrigger?.Execute(); // → Animator.SetTrigger("Jump")
}
}

Mode: OneWayToSource only.


See also