Unity UI Panel with DOTween Animations

VerifiedSafe

Pattern for implementing UI panels with show/hide lifecycle and DOTween animations, including singleton pattern, inspector configuration, and game event reactions.

Sby Skills Guide Bot
DevelopmentIntermediate
107/24/2026
Claude CodeCopilotCursor
#unity#dotween#ui#animation#csharp

Recommended for

Our review

Provides a structured pattern for creating animated UI panels in Unity with DOTween, using UIBase and ITweenAnim.

Strengths

  • Clearly separates UI lifecycle (show/hide) from animation via an ITweenAnim interface.
  • Uses a DOTween animator configurable in the Inspector for flexible animations.
  • Enforces a static singleton for easy access from any script.
  • Includes concrete examples and a ready-to-use template.

Limitations

  • Requires overriding all four UIBase callbacks, even if empty, which can be verbose.
  • Depends on DOTween, an external library that must be imported.
  • Animations are limited to predefined types (DOAnchorPos, Scale, Fade, PunchScale).
When to use it

When you need to add a new animated UI panel or modify an existing one in a Unity project using DOTween.

When not to use it

For very simple UI interactions without animation, or if you want to avoid a dependency on DOTween.

Security analysis

Safe
Quality score85/100

The skill provides a UI coding pattern and template with no executable scripts or destructive instructions; it is purely informational.

No concerns found

Examples

New animated panel with DOTween
Create a new UI panel for player settings using the UIBase/ITweenAnim pattern with a fade-in and scale-out animation, and a singleton accessor.
Modify existing panel to use pattern
Refactor the current score display panel to follow the UIBase pattern with DOTween animations for show/hide.
Add multiple simultaneous animations
Add a new UI panel that slides in from the left while fading in, using multiple AnimSettingDotween under one EAnimIDs in DoTweenUIAnimator.

Use when: adding or modifying any UI panel, HUD element, or animated screen.

Pattern (3 layers — all required)

UIBase          → show/hide lifecycle (_UIBaseShowUI / _UIBaseHideUI)
ITweenAnim      → animation contract (playInAnim / playOutAnim)
DoTweenUIAnimator → DOTween driver, configured entirely in Inspector

Minimal implementation

public class UI_MyPanel : UIBase, ITweenAnim
{
    public static UI_MyPanel s_Instance;
    [SerializeField] DoTweenUIAnimator m_popUp;

    void Awake() { if (s_Instance && s_Instance != this) { Destroy(gameObject); return; } s_Instance = this; }

    public static void ShowUI_s() => s_Instance?._UIBaseShowUI(0.3f);
    public static void HideUI_s() => s_Instance?._UIBaseHideUI(0.3f);

    // UIBase — override all four, even if empty
    protected override void OnCanvasShowBegin() { UpdateUI(); playInAnim(0.3f); }
    protected override void OnCanvasShowEnd()   { }
    protected override void OnCanvasHideBegin() { playOutAnim(0.3f); }
    protected override void OnCanvasHideEnd()   { } // put post-close callbacks here

    public void playInAnim(float d)  => m_popUp.PlayAnimation(DoTweenUIAnimator.EAnimIDs.InAnim, d);
    public void playOutAnim(float d) => m_popUp.PlayAnimation(DoTweenUIAnimator.EAnimIDs.OutAnim, d);
}

Full template with Inspector setup → /project:new-ui-panel

DoTweenUIAnimator quick ref

| Type | Needs | Use for | |---|---|---| | DOAnchorPos | RectTransform | slide in/out | | Scale | RectTransform | pop in/out | | Fade | CanvasGroup | fade in/out | | PunchScale | RectTransform | attention/bounce |

Multiple AnimSettingDotween under one EAnimIDs → play simultaneously.
playOnStart = true on a step → auto-plays on scene load (idle loops, etc).

Reacting to game events in UI

void OnEnable()  => GameManager.AddListener_s(GameConstants.E__GameScoreUpdated, OnScore);
void OnDestroy() => GameManager.RemoveListener_s(GameConstants.E__GameScoreUpdated, OnScore);
void OnScore(object d) { var data = (ScoreUpdateData)d; /* update text */ }

State-change driven UI

UI_ShowScore is the canonical example — OnCanvasHideEnd() calls SetGameState(ToBeStart).
Use this pattern when a panel's close action must drive a game state transition.

Existing singleton panels

| Class | Shows | |---|---| | UI_ShowScore | Post-rally score (static ShowUI_s(myScore, oppScore)) | | UIPopUp | Generic message popup (ShowUI_s(text, onClose)) | | UIGameplayControls | In-game HUD | | UICurrenyHUD | Coin/gold display |

Gotchas

  • Always override all four UIBase callbacks — leaving one unimplemented causes compile error
  • Fade type requires a CanvasGroup on the target — RectTransform alone won't work
  • _UIBaseShowUI(duration) and _UIBaseHideUI(duration) are the only correct entry points — never call gameObject.SetActive() directly
Related skills