TimerStateExtensions
Extension methods for TimerState to control playback.
Read time 2 minutesLast updated 3 hours ago
Definition
- Type: Class
- Namespace: Unity.Animations
- Assembly: UnityEngine.AnimationCoreModule
public static class TimerStateExtensions
Remarks
Call TimerStateExtensions.Play to start a timer, and call TimerStateExtensions.Update once per frame to advance it. A timer advances only while it's playing. The methods modify the timer, so call them on a variable, not on a readonly field or an parameter.
inTo move a timer to another time without playing through the time in between, use one of these methods:
-
TimerStateExtensions.JumpToTime sets the timer to a time that you choose. The time you skip doesn't count as played.
-
TimerStateExtensions.Rewind sets the timer to the start of its range, without changing whether the timer is playing.
If the timer advances in the next after either method, AnimationEventUtility.GatherAnimationEvents includes the animation events at the new time. Both methods apply the TimerState.CycleOffset only when the wrap mode of the timer is WrapMode.Loop.
UpdateThe following example uses the , , , and namespaces. It creates a timer for a clip with Clip.ToTimerState and updates it once per frame.
Unity.AnimationsUnity.EntitiesUnity.IntegerTimeUnityEngineAdditional Resources: TimerState
Examples
// This example plays a clip for a number of frames and returns the state of the timer after the last frame.public static TimerState PlayClip(AnimationClip animationClip, float deltaTime, int frameCount){ using BlobObjectReference<Clip> clipReference = animationClip.ToClipReference(); ref Clip clip = ref clipReference.Value; // Create a playing timer that takes its range, wrap mode, and cycle offset from the clip. TimerState timerState = clip.ToTimerState(DiscreteTime.Zero); // Update the timer once per frame. In a real application, pass the frame delta time. for (int frame = 0; frame < frameCount; ++frame) { timerState.Update(new DiscreteTime(deltaTime)); } // For a one-second clip with Loop Time enabled, three updates of 0.4 seconds // leave the timer at 0.2 seconds, with a loop count of 1. // Without Loop Time, the timer stays at the end of the clip, at 1 second. return timerState;}
Static Methods
Method | Description |
|---|---|
| JumpToTime | Jumps a timer state to a specific time, without advancing the timer from the current time to that time. |
| Pause | Pauses a TimerState, so that it doesn't advance during following updates of the TimerState. The behavior of a TimerState when paused is the same as stopped, the only difference is how other systems interpret those two states. |
| Play | Starts playing a TimerState, so that it advances during all following updates of the TimerState. |
| Rewind | Rewinds a timer state to the start of its range. |
| Stop | Stops a TimerState, so that it doesn't advance during following updates of the TimerState. The behavior of a TimerState when stopped is the same as paused, the only difference is how other systems interpret those two states. |
| Update | Advances a timer by a time step and applies its wrap mode. |