TextureAnim
Coding Style wiki
TextureAnimation is a CPU-computed image sequence animation component. Configure the sprite sequence and playback settings in the Inspector, and it plays on either a SpriteRenderer or an Image, with Normal, Reverse, PingPong, and PingPongReverse play modes and edit-mode preview (ExecuteInEditMode).
| Namespace | OxGKit.Utilities.TextureAnim |
| Type | public class TextureAnimation : MonoBehaviour |
| Source | TextureAnimation.cs |
using OxGKit.Utilities.TextureAnim;
Attention The component must live on an object with a SpriteRenderer or Image (auto-detected in Awake, SpriteRenderer first). Add it via AddComponentMenu: OxGKit/Utilities/TextureAnim/TextureAnimation.
Quick Start
using OxGKit.Utilities.TextureAnim;
using UnityEngine;
public class TextureAnimDemo : MonoBehaviour
{
public TextureAnimation texAnim;
private void Start()
{
// Set the frame rate
this.texAnim.SetFrameRate(12);
// Set the end callback (fires when a non-looping run completes)
this.texAnim.SetAnimationEnd(() =>
{
Debug.Log("Animation Complete");
});
}
public void Replay()
{
// Reset the animation and play from the beginning
this.texAnim.ResetAnim();
}
}
General Rules
Inspector Options
| Field | Description |
|---|---|
Sprites | The image sequence (List of Sprite) used as animation frames in order. |
Is Loop | Whether to loop the playback (default false). |
Play Mode | Play mode: Normal, Reverse, PingPong, PingPongReverse. |
Frame Rate | Playback frame rate (default 30). |
Ignore Time Scale | Whether to ignore Time.timeScale (default true, uses unscaledDeltaTime). |
Playback Behavior
- The animation is driven by
Update, switching sprites at intervals derived fromFrame Rate. - When a non-looping (Is Loop = false) run completes, playback stops on the final frame and the callback set via SetAnimationEnd fires; PingPong / PingPongReverse counts as complete only after one full round trip (two passes).
- The component automatically calls ResetAnim on OnDisable and on Inspector value changes (Editor).
Reminder The animation can be previewed in edit mode (ExecuteInEditMode) without entering Play Mode.
Method Overview
| Method | Description |
|---|---|
| IsAnimationComplete | Checks whether the animation has completed. |
| SetAnimationEnd | Sets the animation end callback. |
| SetIgnoreScale | Sets whether to ignore the time scale. |
| SetFrameRate | Sets the playback frame rate. |
| ResetAnim | Resets the animation to its initial state. |
IsAnimationComplete
public bool IsAnimationComplete()
Checks whether the animation has completed (only non-looping playback reaches the complete state).
SetAnimationEnd
public void SetAnimationEnd(Action endCallback)
Sets the animation end callback, invoked when a non-looping run completes.
texAnim.SetAnimationEnd(() => Debug.Log("Done"));
SetIgnoreScale
public void SetIgnoreScale(bool ignore)
Sets whether to ignore Time.timeScale (true uses unscaledDeltaTime; false uses deltaTime).
SetFrameRate
public void SetFrameRate(int frameRate)
Sets the playback frame rate (minimum 0; the animation does not update at frame rate 0).
ResetAnim
public void ResetAnim()
Resets the animation to its initial state (time, frame index, complete flag, ping-pong pass count) and immediately shows the starting frame.