Skip to main content

NetworkAnimator

A class in Root.Township, Alta.Networking.Animation.

Syncs chosen Animator parameters (floats, ints, bools, triggers, layer weights) from the server to clients as streamed state, and sends the current animation states to joining players. Set values through the Get methods' objects on the server.

Constructors​

MemberWhat it is
NetworkAnimator()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
static AccumulativeAverageCount prepareForWriteTimerShared profiling timer.
static AccumulativeAverageCount serializeTimerShared profiling timer.
18 private and internal fields
MemberWhat it is
private Dictionary<string, AnimatedBool> boolMapBool parameters by name, used by GetBool.
private List<AnimatedBool> boolsSynced bool parameters, set in the inspector.
private Dictionary<string, AnimatedFloatLerp> floatLerpMapLerped float parameters by name, used by GetFloatLerp.
private Dictionary<string, AnimatedFloat> floatMapFloat parameters by name, used by GetFloat.
private List<AnimatedFloat> floatsSynced float parameters, set in the inspector.
private List<AnimatedFloatLerp> floatsLerpSynced float parameters that clients lerp toward, set in the inspector.
private Dictionary<string, AnimatedInt> intMapInt parameters by name, used by GetInt.
private List<AnimatedInt> intsSynced int parameters, set in the inspector.
private bool isAwakeSet once EnsureAwake has built the maps.
private Dictionary<string, AnimatedLayerWeightLerp> layerLerpMapLerped layer weights by name, used by GetLayerWeightLerp.
private Dictionary<string, AnimatedLayerWeight> layerMapLayer weights by name, used by GetLayerWeight.
private List<AnimatedLayerWeight> layersSynced layer weights, set in the inspector.
private List<AnimatedLayerWeightLerp> layersLerpSynced layer weights that clients lerp toward, set in the inspector.
private static Logger loggerNLog logger, used for missing parameter errors.
private MethodSync syncStartMethod sync made in Initialize that sends the animator state to a player on connect.
private Dictionary<string, AnimatedTrigger> triggerMapTrigger parameters by name, used by GetTrigger.
private List<AnimatedTrigger> triggersSynced trigger parameters, set in the inspector.
private Animator unityAnimatorBacking field for Animator, the Unity Animator on this object.

Properties​

MemberWhat it is
Animator Animator { get; }The Unity Animator on this object.
bool HasChanged { get; private set; }True if any synced value changed and needs sending.
3 private and internal properties
MemberWhat it is
private int Alta.Networking.INetworkSerialized.MaximumBits { get; }Caps this behaviour's serialized data at 512 bits.
private AccumulativeAverageCount Alta.Networking.INetworkSerialized.PrepareForWriteTimer { get; }Returns the shared prepareForWriteTimer profiling counter.
private AccumulativeAverageCount Alta.Networking.INetworkSerialized.SerializeTimer { get; }Returns the shared serializeTimer profiling counter.

Methods​

MemberWhat it is
void EnsureAwake()Builds the parameter lookups, logging any listed parameter the animator does not have. Safe to call more than once.
void ForceChanged()Marks the parameters as changed so they are sent.
AnimatedBool GetBool(string name)The synced bool parameter with this name. Throws if not listed.
AnimatedFloat GetFloat(string name)The synced float parameter with this name. Throws if not listed.
AnimatedFloatLerp GetFloatLerp(string name)The synced smoothed float parameter with this name. Throws if not listed.
AnimatedInt GetInt(string name)The synced int parameter with this name. Throws if not listed.
AnimatedLayerWeight GetLayerWeight(string name)The synced layer weight with this name. Throws if not listed.
AnimatedLayerWeightLerp GetLayerWeightLerp(string name)The synced smoothed layer weight with this name. Throws if not listed.
AnimatedTrigger GetTrigger(string name)The synced trigger with this name. Throws if not listed.
override void Initialize()Sets up the message that sends current animation states.
override void OnConnected(Player player)Server: sends a joining player each layer's current state and time.
void UpdateChanged()Recomputes HasChanged from the parameters.
7 private and internal methods
MemberWhat it is
private void Awake()Calls EnsureAwake to build the parameter maps.
private void LogMissingParameter(string parameterType, string parameterName)Logs an error when a configured parameter isn't on the Animator.
private void IBuildRendererPostBake.PostBake()Build bake hook: initialises every configured parameter against the Animator, logging missing ones.
private bool Alta.Networking.INetworkSerialized.PrepareForWrite(bool isWriteFull)Returns HasChanged, so the animator only writes when a parameter changed.
private void Alta.Networking.INetworkSerialized.Serialize(Stream stream, bool isWriteFull)Writes or reads floats, layers, ints and lerped values, then bools and triggers behind an any-set flag.
private void SyncStart(IPlayer player, Stream stream)Method sync: sends each layer's current state hash and normalized time so a joining client plays the same state.
private void Update()Steps every lerped float and lerped layer weight toward its target.

Used in​

Members of other types that take, return or hold a NetworkAnimator: