Skip to main content

TextureAnim

Important Attention Reminder

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).

NamespaceOxGKit.Utilities.TextureAnim
Typepublic class TextureAnimation : MonoBehaviour
SourceTextureAnimation.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

FieldDescription
SpritesThe image sequence (List of Sprite) used as animation frames in order.
Is LoopWhether to loop the playback (default false).
Play ModePlay mode: Normal, Reverse, PingPong, PingPongReverse.
Frame RatePlayback frame rate (default 30).
Ignore Time ScaleWhether to ignore Time.timeScale (default true, uses unscaledDeltaTime).

Playback Behavior

  • The animation is driven by Update, switching sprites at intervals derived from Frame 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

MethodDescription
IsAnimationCompleteChecks whether the animation has completed.
SetAnimationEndSets the animation end callback.
SetIgnoreScaleSets whether to ignore the time scale.
SetFrameRateSets the playback frame rate.
ResetAnimResets 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.