DoTweenAnimEvent
Coding Style wiki
DoTweenAnimEvent is the tween animation group player of TweenSystem. It plays multiple DoTweenAnims together in Parallel or Sequence mode, providing forward (PlayNormal), backward (PlayReverse), and trigger toggle (PlayTrigger) play methods with end callbacks (endCallback). Add it via Add Component/OxGKit/TweenSystem/DoTweenAnimEvent.
| Namespace | OxGKit.TweenSystem |
| Type | public class DoTweenAnimEvent : MonoBehaviour |
| Source | DoTweenAnimEvent.cs |
using OxGKit.TweenSystem;
Important DoTweenAnimEvent only plays at runtime; it does not support editor preview (Preview Mode only supports DoTweenAnim, refer to the Module Intro).
Quick Start
using DG.Tweening;
using OxGKit.TweenSystem;
using UnityEngine;
public class PanelController : MonoBehaviour
{
// Configure the Do Tween Anims list in the Inspector (DriveMode set to Event)
[SerializeField]
private DoTweenAnimEvent _panelAnim;
// Open panel (plays forward)
public void OpenPanel()
{
this._panelAnim.PlayNormal(() => Debug.Log("Panel opened"));
}
// Close panel (plays backward)
public void ClosePanel()
{
this._panelAnim.PlayReverse(() => this.gameObject.SetActive(false));
}
}
General Rules
PlayMode
public enum PlayMode
{
Parallel, // Parallel playback (all at once)
Sequence // Sequential playback (one by one in list order)
}
- Parallel: all DoTweenAnims in the list play at the same time; the
endCallbackfires after the longest duration finishes. - Sequence: plays one by one in list order; each DoTweenAnim finishes (measured by its longest track duration) before the next one starts, and the
endCallbackfires after all of them finish.
Trigger Direction (trigger)
- trigger = true plays forward (normal); trigger = false plays backward (reverse).
- Each DoTweenAnim plays forward or backward according to its own tracks' playMode (see DoTweenAnim).
Attention The DoTweenAnims in the list should have their DriveMode set to Event (Active mode replays automatically on activation, do not mix them); also, every DoTweenAnim must have at least one tween track enabled, otherwise a NullReferenceException occurs when computing the group duration.
Members
| Member | Description |
|---|---|
public PlayMode playMode | Group play mode (default Parallel), Inspector: Play Mode. |
public List<DoTweenAnim> doTweenAnims | The controlled DoTweenAnim list, Inspector: Do Tween Anims. |
Play Control
Overview
| Method | Description |
|---|---|
| PlayNormal | Plays forward. |
| PlayReverse | Plays backward. |
| PlayTrigger | Trigger playback (auto-flip or explicit direction). |
| PlayTriggerOnce | Plays only once when the trigger direction changes. |
| ResetTrigger | Resets the trigger flag. |
| Kill | Kills the current group play sequence. |
PlayNormal
public void PlayNormal()
public void PlayNormal(TweenCallback endCallback = null)
Plays forward (trigger = true) all DoTweenAnims in the list; the endCallback fires after all of them finish playing.
this._panelAnim.PlayNormal(() => Debug.Log("All tweens ended"));
PlayReverse
public void PlayReverse()
public void PlayReverse(TweenCallback endCallback = null)
Plays backward (trigger = false) all DoTweenAnims in the list; the endCallback fires after all of them finish playing.
this._panelAnim.PlayReverse(() => this.gameObject.SetActive(false));
PlayTrigger
public void PlayTrigger()
public void PlayTrigger(TweenCallback endCallback = null)
public void PlayTrigger(bool trigger, TweenCallback endCallback = null)
Trigger playback: the overloads without a trigger parameter automatically record and flip the trigger flag (direction alternates on each call); the overload with an explicit trigger plays according to the parameter (true = forward, false = backward).
// Alternates direction on each call (open -> close -> open...)
this._panelAnim.PlayTrigger();
// Explicit direction + end callback
this._panelAnim.PlayTrigger(true, () => Debug.Log("Played normally"));
PlayTriggerOnce
public void PlayTriggerOnce(bool trigger)
public void PlayTriggerOnce(bool trigger, TweenCallback endCallback = null)
Plays only when the trigger differs from the last recorded state (true = forward, false = backward), preventing replays of the same state; ideal for Toggle-style UI.
// Play on toggle change (no replay for the same state)
toggle.onValueChanged.AddListener((isOn) =>
{
toggle.GetComponent<DoTweenAnimEvent>().PlayTriggerOnce
(
isOn,
() => Debug.Log("Toggle tween finished")
);
});
ResetTrigger
public void ResetTrigger()
Resets the trigger flag (back to false), affecting the flip starting point of PlayTrigger and the state comparison of PlayTriggerOnce.
Kill
public void Kill()
Kills the current group play sequence (each play method also kills the previous sequence automatically before playing again).
Reminder Call Kill() before a UI object is destroyed or recycled to prevent the endCallback from being invoked on a destroyed object.
List Management
Overview
| Method | Description |
|---|---|
| SetPlayMode | Sets the group play mode. |
| AddDoTweenAnim | Dynamically adds one or more DoTweenAnims (chainable). |
| RemoveDoTweenAnim | Removes a specific DoTweenAnim. |
| ClearDoTweenAnims | Clears the list. |
SetPlayMode
public void SetPlayMode(PlayMode playMode)
Sets the group play mode (Parallel / Sequence).
AddDoTweenAnim
public DoTweenAnimEvent AddDoTweenAnim(params DoTweenAnim[] doTweenAnims)
Dynamically adds one or more DoTweenAnims to the list; returns itself for chained calls.
animEvent
.AddDoTweenAnim(anim1, anim2)
.PlayNormal(() => Debug.Log("Played"));
RemoveDoTweenAnim
public void RemoveDoTweenAnim(DoTweenAnim doTweenAnim)
Removes a specific DoTweenAnim from the list.
ClearDoTweenAnims
public void ClearDoTweenAnims()
Clears the entire DoTweenAnim list.