Skip to main content

DoTweenAnim

Important Attention Reminder

Coding Style wiki


DoTweenAnim is the tween animation component of TweenSystem (based on DoTween Pro). Enable and configure tween tracks (Position, Rotation, Scale, Size, Alpha, Color) in the Inspector; each track supports Normal, Reverse, PingPong, Sequence play modes. Choose the DriveMode to play either automatically on activation (Active) or event-driven (Event), with editor Preview Mode support. Add it via Add Component/OxGKit/TweenSystem/DoTweenAnim (only one per GameObject).

NamespaceOxGKit.TweenSystem
Typepublic class DoTweenAnim : MonoBehaviour
SourceDoTweenAnim.cs
using OxGKit.TweenSystem;

Attention The end callback type is DoTween's TweenCallback (DG.Tweening); add using DG.Tweening; when using callbacks.

Quick Start

using DG.Tweening;
using OxGKit.TweenSystem;

// 1. Add Component/OxGKit/TweenSystem/DoTweenAnim
// 2. Enable tween tracks in the Inspector (tPositionOn, tScaleOn...)
// and configure from/to values, duration, easeMode, playMode

// DriveMode.Active: plays automatically when the GameObject becomes active
doTweenAnim.gameObject.SetActive(true);

// DriveMode.Event: driven by code (or DoTweenAnimEvent)
doTweenAnim.PlayTween(true); // Play forward
doTweenAnim.PlayTween(false, () => Debug.Log("Play ended")); // Play backward + end callback

General Rules

Tween Tracks

After enabling a track toggle, the Inspector shows the corresponding track configuration (TweenValues); tracks that require a component auto-find the component on the same GameObject during initialization, and the track does not play if the component is not found:

ToggleTrack (Type)Tween Target (DoTween)Required Component (auto find)
tPositionOntPosition (TweenPosition)Position (DOLocalMove)Transform
tRotationOntRotation (TweenRotation)Rotation (DOLocalRotate / DOLocalRotateQuaternion)Transform
tScaleOntScale (TweenScale)Scale (DOScale)Transform
tSizeOntSize (TweenSize)Size (DOSizeDelta)RectTransform
tAlphaOntAlpha (TweenAlpha)Alpha (DOFade)CanvasGroup
tImgColorOntImgColor (TweenImgColor)Color (DOColor)Image
tSprColorOntSprColor (TweenSprColor)Color (DOColor)SpriteRenderer

PlayMode

public enum PlayMode
{
Normal, // Plays forward (from -> to)
Reverse, // Plays backward (to -> from)
PingPong, // Plays back and forth (from -> to -> from)
Sequence // Plays along the waypoint list in order
}

Attention In Sequence mode, from / to (begin / end) values are ignored; use the track's waypoint list instead (posSeq, angleSeq, scaleSeq, sizeSeq, alphaSeq, colorSeq).

DriveMode

public enum DriveMode
{
Active, // Plays automatically on activation (SetActive-driven)
Event // Event-driven playback (DoTweenAnimEvent or code)
}
  • Active: automatically resets and plays on OnEnable, and resets back to the origin values on OnDisable; loop settings (loopTimes / loopType) and interval replay (isInterval / intervalTime) take effect in this mode.
  • Event: waits for an external call to PlayTween (usually driven by DoTweenAnimEvent as a group); the trigger decides forward/backward and it plays a single pass (loop settings are not applied). When the Inspector's Auto Active option is on, Awake automatically hides the GameObject with SetActive(false), and the GameObject is also deactivated automatically after a backward play (trigger = false) finishes.

Important Pick only one drive style per DoTweenAnim: Active mode replays automatically on every activation, so do not also drive the same component through a DoTweenAnimEvent.

Ignore Time Scale

The Inspector's Ignore Time Scale option (default true) is applied to all tracks: tweens are not affected by Time.timeScale (they keep playing in pause menus); interval replay timing also uses unscaledDeltaTime or deltaTime according to this option.

Editor Preview (Preview Mode)

  • The Editor block at the bottom of the Inspector provides preview playback: Active mode shows a Play button and a Progress slider; Event mode shows an alternating Play Trigger (true / false) button; the Stop button stops the preview and restores the origin values.
  • When the Is Sync Begin Value option is on, editing the track configuration automatically syncs the begin values onto the GameObject (OnValidate).
  • During preview (isPreviewMode) the tween settings are locked, and loop times are forced to 0 (single pass).
  • Editing in the scene is not allowed during Play Mode; only editing in Prefab Isolation mode is supported.
  • See the preview illustration in the Module Intro.

Members

MemberDescription
public DriveMode driveModeDrive mode (default Active), Inspector: Drive Mode (see DriveMode).
public bool tPositionOn ... public bool tSprColorOnThe seven track toggles (all default false), see Tween Tracks.
public TweenPosition tPosition ... public TweenSprColor tSprColorRead-only accessors for the seven track configurations (read seq, duration, etc. at runtime).
public static bool isPreviewMode(UNITY_EDITOR) Whether the editor preview mode is currently active.

Common Track Configuration (TweenBase)

All tracks inherit the common configuration from TweenBase:

[Serializable]
public class TweenBase
{
public bool isInterval; // Interval replay toggle (only effective in DriveMode.Active)
public float intervalTime; // Interval time (shown when isInterval = true)
public int loopTimes; // Loop times, -1 = infinitely (shown when isInterval = false)
public LoopType loopType; // Loop type (default Restart)
public PlayMode playMode; // Play mode (default Normal)
public Ease easeMode; // Ease mode (default Linear)
public float duration; // Duration time (default 0.1f)
}

Track-specific configuration:

TrackSpecific Configuration
TweenPositionrelative (tween relative to its own position), from / to (Vector3), posSeq (List<Vector3>)
TweenRotationrotateMode (default FastBeyond360), beginAngle / endAngle (Vector3), angleSeq (List<Vector3>)
TweenScalebeginScale / endScale (Vector3), scaleSeq (List<Vector3>)
TweenSizebeginSize / endSize (Vector2), sizeSeq (List<Vector2>)
TweenAlphabeginAlpha / endAlpha (float, 0 ~ 1), alphaSeq (List<float>)
TweenImgColorbeginColor / endColor (Color), colorSeq (List<Color>)
TweenSprColorbeginColor / endColor (Color), colorSeq (List<Color>)

Methods

Overview

MethodDescription
PlayTween(Event-driven) Plays all enabled tracks; trigger controls the direction.
InitTweensInitializes all enabled tracks (binds components and records origin values).
ResetTweensKills all tweens and resets back to the origin values.
GetMaxDurationTweenGets the track with the longest duration.

PlayTween

public void PlayTween(bool trigger, TweenCallback endCallback = null)

(Event-driven) Plays all enabled tracks: automatically activates the GameObject with SetActive(true) → resets the tracks → attaches endCallback (and Auto Active) to the track with the longest duration → plays each track according to its playMode.

  • trigger: true plays forward; false plays backward (inverse).
  • endCallback: fires when the track with the longest duration finishes playing.
// Play forward
doTweenAnim.PlayTween(true);

// Play backward + end callback
doTweenAnim.PlayTween(false, () => Debug.Log("Tween ended"));

Reminder In most cases it is recommended to use DoTweenAnimEvent for group playback and callback management instead of calling this method directly.

InitTweens

public void InitTweens()

Initializes all enabled tracks: binds the components on the same GameObject (Transform / RectTransform / CanvasGroup / Image / SpriteRenderer) and records the origin values according to the playMode (Awake calls this automatically; call it manually after changing track configurations dynamically at runtime).

ResetTweens

public void ResetTweens()

Kills all track tween sequences and resets the values back to the origin values (OnDisable (Active mode) and OnDestroy call this automatically).

GetMaxDurationTween

public TweenBase GetMaxDurationTween()

Gets the track (TweenBase) with the longest duration among the enabled tracks; returns null when no track is enabled.

Attention DoTweenAnimEvent calls this method to compute the group wait time when playing, so every DoTweenAnim in its list must have at least one tween track enabled, otherwise a NullReferenceException occurs.