AnimationSynchronizable Class

Synchronizable Animator component.

Definition

Namespace: Alteruna
Assembly: Alteruna.Trinity (in Alteruna.Trinity.dll) Version: 1.3.4+03e8eebec78141d9d3b2022fda2c0ac58d3116b9
C#
public class AnimationSynchronizable : AttributesSync
Inheritance
Object    Object    Component    Behaviour    MonoBehaviour    CommunicationBridge    CommunicationBridgeUID    AttributesSync    AnimationSynchronizable

Remarks

In most cases, you should avoid synchronizing the animations as they are usually not deterministic and can be performed from actions directly. For example, instead of playing walk animation, you should consider animating based on the velocity of the character locally.

Example

AnimationSynchronizable is used together with the Unity Animator. Adding a AnimationSynchronizable component to a GameObject will automatically add the Animator component. To sync using the AnimationSynchronizable component, you need to call the method from the AnimationSynchronizable component.
C#
using UnityEngine;

[RequireComponent(typeof(Alteruna.AnimationSynchronizable))]
   public class MyAnimatedObj : MonoBehaviour
   {
       private Alteruna.AnimationSynchronizable _aniSync;

       // We can optimize by precalculating the hash of the animation state.
       private int JumpId = Animator.StringToHash("Jump");

       private void Start()
       {
           _aniSync = GetComponent<Alteruna.AnimationSynchronizable>();

           // We can get the Unity Animator from the AnimationSynchronizable component.
           if (_aniSync.Animator.isHuman) print("Humanoid");
       }

       private void Update()
       {
           // Play animation
           if (Input.GetKeyDown(KeyCode.Space))
           {
               // play for all clients
               _aniSync.Play(JumpId);
           }
       }
   }

Methods

Fields

Animator 
OnlyCommitNewStates If true, only commit new states in SetBool, SetInteger, and SetFloat methods.

See Also