Class TinyAnimation
A collection of utility methods to control the playback of animation clips.
Namespace: Unity.Tiny.Animation
Syntax
public static class TinyAnimation
Remarks
Most of the TinyAnimation methods require both a World and an Entity to perform the required operations. The entity parameter is always the player Entity identifying the data with which to perform the operation. This entity must have a TinyAnimationClipRef buffer component, which contains a list of animation clips, and a TinyAnimationPlayer component, which identifies an animation clip in that list. The clip identified by TinyAnimationPlayer is the animation affected by subsequent calls to TinyAnimation functions. For example, to play a specifc clip in the TinyAnimationClipRef list, first call SelectClip(World, Entity, Int32), which updates the TinyAnimationPlayer data, and then call Play(World, Entity).
The world parameter always represents the World in which the player entity exists.
Methods
GetClipsCount(World, Entity)
The number of animation clips associated with the specified entity.
Declaration
[PublicAPI]
public static int GetClipsCount(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Returns
Type | Description |
---|---|
Int32 | The number of clips in the TinyAnimationClipRef buffer of this entity. |
GetCurrentClipHash(World, Entity)
The hashed name used as an identifier for the clip currently selected for playback on the specified entity.
Declaration
[PublicAPI]
public static uint GetCurrentClipHash(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Returns
Type | Description |
---|---|
UInt32 | The hashed value used to identify the currently selected clip. |
See Also
GetCurrentClipIndex(World, Entity)
The index of the clip currently selected for playback on the specified entity.
Declaration
[PublicAPI]
public static int GetCurrentClipIndex(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Returns
Type | Description |
---|---|
Int32 | The index, in the TinyAnimationClipRef buffer, of the currently selected clip. |
GetCycleOffset(World, Entity)
Gets the cycle offset of the currently selected animation clip.
Declaration
[PublicAPI]
public static float GetCycleOffset(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Returns
Type | Description |
---|---|
Single | The normalized cycle offset for the currently selected clip. |
Remarks
The cycle offset is a normalized value between 0.0 and 1.0 representing a percentage of the duration of the clip.
See Also
GetDuration(World, Entity)
Gets the duration of the currently selected animation clip.
Declaration
[PublicAPI]
public static float GetDuration(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Returns
Type | Description |
---|---|
Single | The duration in seconds, of the currently selected clip. |
See Also
GetDuration(World, Entity, Int32)
Declaration
[PublicAPI]
[Obsolete("GetDuration(World, Entity, int) has been renamed to GetDurationAtIndex. (RemovedAfter 2020-10-30). (UnityUpgradable) -> GetDurationAtIndex(*)", true)]
public static float GetDuration(World world, Entity entity, int clipIndex)
Parameters
Type | Name | Description |
---|---|---|
World | world | |
Entity | entity | |
Int32 | clipIndex |
Returns
Type | Description |
---|---|
Single |
GetDuration(World, Entity, UInt32)
Gets the duration of the specified animation clip.
Declaration
[PublicAPI]
public static float GetDuration(World world, Entity entity, uint clipHash)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
UInt32 | clipHash | The hashed name of the animation clip asset whose duration you want to know. You can obtain a hashed name by using StringToHash(String). |
Returns
Type | Description |
---|---|
Single | The duration in seconds, of the specified clip. |
See Also
GetDurationAtIndex(World, Entity, Int32)
Gets the duration of the animation clip stored at the specified index.
Declaration
[PublicAPI]
public static float GetDurationAtIndex(World world, Entity entity, int clipIndex)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Int32 | clipIndex | The index of the clip whose duration you want to know. |
Returns
Type | Description |
---|---|
Single | The duration in seconds, of the clip at the specified index. |
Remarks
There are no guarantees for the order in which the clips are stored. If you want to know the duration of a specific clip, we recommend using its hash with GetDuration(World, Entity, UInt32).
See Also
GetDurations(World, Entity, Allocator)
Gets the duration of all the animation clips associated with the specified Entity.
Declaration
[PublicAPI]
public static NativeArray<float> GetDurations(World world, Entity entity, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Allocator | allocator | The allocator to use for the creation of the NativeArray<T>. You can use Temp if you are going to use the results immediately (in the same scope that you call this function). Otherwise, use TempJob or Persistent and dispose of the returned array when done. |
Returns
Type | Description |
---|---|
NativeArray<Single> | A native array of floats containing the duration of every clip associated with |
Remarks
The order of the durations in the returned array matches the order in which the clips are stored.
See Also
GetTime(World, Entity)
Gets the time in seconds at which the currently selected animation clip will be or was evaluated during this frame.
Declaration
[PublicAPI]
public static float GetTime(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Returns
Type | Description |
---|---|
Single | The time in seconds at which the currently selected clip is being evaluated. |
Remarks
The clip time is a value, in seconds, between 0 and the duration of the clip.
GetWrapMode(World, Entity)
Gets the WrapMode of the currently selected animation clip.
Declaration
[PublicAPI]
public static WrapMode GetWrapMode(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Returns
Type | Description |
---|---|
WrapMode | The WrapMode of the currently selected clip. |
See Also
IsPaused(World, Entity)
Reports whether the currently selected animation clip is paused.
Declaration
[PublicAPI]
public static bool IsPaused(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Returns
Type | Description |
---|---|
Boolean | Whether the currently selected animation clip is paused or not. |
Remarks
An animation clip is paused when its Entity has the ApplyAnimationResultTag tag but doesn't have the UpdateAnimationTimeTag tag.
IsPlaying(World, Entity)
Reports whether the currently selected animation clip is playing.
Declaration
[PublicAPI]
public static bool IsPlaying(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Returns
Type | Description |
---|---|
Boolean | Whether the currently selected animation clip is playing or not. |
Remarks
An animation clip is playing when its Entity has both the UpdateAnimationTimeTag and the ApplyAnimationResultTag tags.
IsStopped(World, Entity)
Reports whether the currently selected animation clip is stopped.
Declaration
[PublicAPI]
public static bool IsStopped(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Returns
Type | Description |
---|---|
Boolean | Whether the currently selected animation clip is stopped or not. |
Remarks
An animation clip is stopped when its Entity has neither the ApplyAnimationResultTag or the UpdateAnimationTimeTag tag.
Pause(World, Entity)
Pauses playback of the currently selected animation clip.
Declaration
[PublicAPI]
public static void Pause(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Remarks
This operation takes effect at the beginning of the next frame.
Play(World, Entity)
Starts or resumes playback of the currently selected animation clip.
Declaration
[PublicAPI]
public static void Play(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Remarks
This operation takes effect at the beginning of the next frame.
SelectClip(World, Entity, Int32)
Declaration
[PublicAPI]
[Obsolete("SelectClip(World, Entity, int) has been renamed to SelectClipAtIndex. (RemovedAfter 2020-10-30). (UnityUpgradable) -> SelectClipAtIndex(*)", true)]
public static void SelectClip(World world, Entity entity, int clipIndex)
Parameters
Type | Name | Description |
---|---|---|
World | world | |
Entity | entity | |
Int32 | clipIndex |
SelectClip(World, Entity, String)
Selects an animation clip for playback using its clip name.
Declaration
[PublicAPI]
public static void SelectClip(World world, Entity entity, string clipName)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
String | clipName | The name of the animation clip asset to select for playback. |
Remarks
After you select a clip, subsequent calls to Play(World, Entity), Pause(World, Entity), SetTime(World, Entity, Single), etc. apply to the selected clip.
Selecting a new animation clip does not change the current playback status. If the previous clip was playing, the new clip continues playing. If the previous clip was paused, playback remains paused.
Selecting a clip using its name is very inefficient and unless you have a good reason for using it, we recommend selecting clips by Hash value using the SelectClip(World, Entity, UInt32) overload instead.
SelectClip(World, Entity, UInt32)
Selects an animation clip for playback using its hash.
Declaration
[PublicAPI]
public static void SelectClip(World world, Entity entity, uint clipHash)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
UInt32 | clipHash | The hashed name of the animation clip asset to select for playback. You can obtain a hashed name by using StringToHash(String). |
Remarks
Selecting a new animation clip does not change the current playback status. If the previous clip was playing, the new clip continues playing. If the previous clip was paused, playback remains paused.
SelectClipAtIndex(World, Entity, Int32)
Selects an animation clip for playback using its index into the TinyAnimationClipRef buffer
of entity
.
Declaration
[PublicAPI]
public static void SelectClipAtIndex(World world, Entity entity, int clipIndex)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Int32 | clipIndex |
Remarks
After you select a clip, subsequent calls to Play(World, Entity), Pause(World, Entity), SetTime(World, Entity, Single), etc. apply to the selected clip.
Selecting a new animation clip does not change the current playback status. If the previous clip was playing, the new clip continues playing. If the previous clip was paused, playback remains paused.
Selecting a clip by index is unpredictable: there are no guarantees for the order in which the clips are stored. This method is useful if you want to play a random clip; otherwise, we recommend selecting a clip by its hash using SelectClip(World, Entity, UInt32).
SelectNextClip(World, Entity)
Selects the next clip in the list of available clips for playback.
Declaration
[PublicAPI]
public static void SelectNextClip(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Remarks
After you select a clip, subsequent calls to Play(World, Entity), Pause(World, Entity), SetTime(World, Entity, Single), etc. apply to the selected clip.
This operation is cyclical, meaning that once it reaches the end of the list, the next clip is the first one in the list. Therefore, this method is always safe to call and will never go out of bounds.
There are no guarantees for the order in which the clips are stored. Use this method only if you want to cycle randomly through a list of clips. If you need precise control over which clip plays when, we recommend using SelectClip(World, Entity, UInt32).
SelectPreviousClip(World, Entity)
Selects the previous clip in the list of available clips for playback.
Declaration
[PublicAPI]
public static void SelectPreviousClip(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Remarks
After you select a clip, subsequent calls to Play(World, Entity), Pause(World, Entity), SetTime(World, Entity, Single), etc. apply to the selected clip.
This operation is cyclical, meaning that once it reaches the first clip of the list, the previous clip is the last one in the list. Therefore, this method is always safe to call and will never go out of bounds.
There are no guarantees for the order in which the clips are stored. Use this method only if you wand to cycle randomly through a list of clips. If you need precise control over which clip plays when, we recommend using SelectClip(World, Entity, UInt32).
SetCycleOffset(World, Entity, Single)
Sets the cycle offset for the currently selected animation clip.
Declaration
[PublicAPI]
public static void SetCycleOffset(World world, Entity entity, float cycleOffset)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Single | cycleOffset | The desired cycle offset. |
Remarks
The cycle offset is a normalized value between 0.0 and 1.0 representing a percentage of the duration of the clip.
See Also
SetTime(World, Entity, Single)
Specifies the time in seconds at which the currently selected animation should be evaluated.
Declaration
[PublicAPI]
public static void SetTime(World world, Entity entity, float newTime)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Single | newTime | The time in seconds at which you want to evaluate the currently selected clip. |
Remarks
The newTime
value is clamped between 0 and the duration of the clip, in
accordance with the rules of the WrapMode associated with the clip.
If the animation clip is playing, it is very likely that the delta time for the frame will be added to the time specified.
See Also
SetWrapMode(World, Entity, WrapMode)
Sets the WrapMode for the currently selected animation clip.
Declaration
[PublicAPI]
public static void SetWrapMode(World world, Entity entity, WrapMode wrapMode)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
WrapMode | wrapMode | The desired WrapMode |
See Also
Stop(World, Entity)
Stops playback of the currently selected animation clip. A stopped clip has it's time set to 0.
Declaration
[PublicAPI]
public static void Stop(World world, Entity entity)
Parameters
Type | Name | Description |
---|---|---|
World | world | The world containing |
Entity | entity | The entity on which to perform the operation.
Note that |
Remarks
This operation takes effect at the beginning of the next frame.
StringToHash(String)
A simple hashing function used to generate efficient deterministic identifiers for animation clips.
Declaration
[PublicAPI]
public static uint StringToHash(string source)
Parameters
Type | Name | Description |
---|---|---|
String | source | The string to hash. Generally, the name of the animation clip asset. |
Returns
Type | Description |
---|---|
UInt32 | The hashed value for the input string. |