Documentation

Unity Engine

Unity Engine

AnimatableFloatChannels

A set of named float channels that a script component exposes to the animation system.
Read time 2 minutesLast updated a day ago

Definition

public sealed class AnimatableFloatChannels : IEnumerable<KeyValuePair<string, float>>, IEnumerable

Remarks

Declare a serialized field of this type on a MonoBehaviour to make each of its channels animatable, the same way a SkinnedMeshRenderer makes each blend shape animatable. A channel appears in the Animation window as
<field>.<channel>
, where
<field>
is the name of the field. For example, a channel named
Smile
in a field named
expressions
appears as
expressions.Smile
. Channel names can contain periods.
The field must be public or have the SerializeField attribute. Fields with the
[NonSerialized]
attribute and
readonly
fields aren't animatable.
The component decides which channels exist. Call AnimatableFloatChannels.SetChannels whenever the set changes, for example when a different sprite is assigned. The channel names and values are saved with the component.
When an animation changes the value of a channel, Unity sends the
OnDidApplyAnimationProperties
message to the component, in the same way as for an animated field.
The following example exposes two channels and logs their values when an animation changes them.
using UnityEngine;public class FaceExpressions : MonoBehaviour{ // Animate these channels as "expressions.Smile" and "expressions.Blink". public AnimatableFloatChannels expressions = new AnimatableFloatChannels(); // Reset runs when you add the component in the Editor. The channel names are saved with the component. void Reset() { expressions.SetChannels("Smile", "Blink"); } void OnDidApplyAnimationProperties() { foreach (var channel in expressions) Debug.Log(channel.Key + ": " + channel.Value); }}

Constructors

Constructor

Description

AnimatableFloatChannels()Creates an empty channel set.

Properties

Property

Description

channelCountThe number of channels in the set.
this[]The value of the channel at a position in the set.

Methods

Method

Description

GetChannelNameGets the name of the channel at a position in the set.
GetEnumeratorGets an enumerator that iterates over the name and value of each channel, in the order of the set.
IndexOfFinds the position of a channel in the set by name.
SetChannelsReplaces the channel set with channels that have the given names.

Structs

Struct

Description

AnimatableFloatChannels.EnumeratorEnumerates the name and value of each channel in an AnimatableFloatChannels set.