Skip to content
CatCodeGamesPublic

About

Clean Unity UI modal & dialog window system built with MVP and a pure C# engine-independent core. Supports queue/stack transitions, Addressables, UniTask

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

ModalDemo

English | Русский

A technical demo of a reusable modal window module for Unity. The module manages window presentation and lifecycle.

The module is in Assets/Modals, and the demo scene with sample windows is in Assets/Demo.

  • Simple, general-purpose API. Opening and controlling windows relies on standard C# primitives and does not require async/await on the caller side.
  • MVP architecture. Business logic is separated from the visual layer and connected through a thin Presenter.
  • Pure C# core. Service, lifecycle, and factory logic have no dependency on UnityEngine.
  • Addressables loading. Window prefabs are loaded on demand via Addressables in a separate optional assembly.
  • Swappable visuals. The same logic and factory can open different prefabs depending on the request.
  • Interface-based contracts. Stage, factories, and window instances are defined as interfaces, making them easy to replace or mock in tests.

Usage

// Open a window that closes itself (e.g. via OK / Cancel).
modals.Show(
    new MessageWindowRequest(model, MessageWindowStyle.Alert),
    mode: ModalShowMode.Push);

// Await a specific stage (Open, Closed, etc.).
// Leaving the block or cancelling `ct` disposes the handle and softly closes the window.
var status = new EventValue<ModalStatus>(default, NotificationMode.OnChange);
using var modal = modals.Show(request, s => status.Value = s);

await status.WaitAsync(static s => s.Lifecycle == ModalLifecycleState.Open, ct);
await status.WaitAsync(static s => s.Lifecycle == ModalLifecycleState.Closed, ct);

Public API (IModalService)

Member Description
Show(request, onStatusChanged, mode) Queues a window and returns a ModalHandle. Status callback is optional.
ModalHandle struct : IDisposable. Dispose() requests a soft close (CloseReason.Handle).
ModalStatus Current stage (Queued, Loading, Showing, Open, Closing, Closed) and close reason (Self, Handle, QueueCleared, Force, Failed).
ModalShowMode Enqueue (FIFO, waits until no windows are open) / Push (LIFO, opens on top).
IsActive IReadOnlyEventValue<bool> — true while any window is queued or open.
TryHandleBack() Esc / outside click: returns Handled, Blocked, or NotHandled.
ClearQueue() / CloseAll() Clears queued windows / softly closes all windows.
ForceCloseAll() Immediately closes all windows, ignoring IsBusy and skipping animations.

Architecture

Caller          modals.Show(request, onStatus)
   │
ModalService    queue + sequential loop: load → show → wait → hide
   │
ModalWindow     single-window lifecycle and status
   │
 ┌─┴────────────────┐
Factories          Stage
request → prefab    layers, dimming, and transition animations
   │                │
   └──── ModalInstance (ModalShell + Presenter) ────┘
               │
        MVP: Model → Presenter → View
  • ModalService — owns the Enqueue/Push queue and runs all transitions sequentially in a single loop.
  • ModalWindow — owns one window's lifecycle and ModalStatus; routes close requests from ModalHandle, Presenter, and service through one path (first reason wins).
  • MVP — Model (plain data, no reference to Modals), Presenter (behavior, IsBusy, close requests), View (UI only).
  • ModalStage / ModalShell — Active, Transition, and Passive layers, interactivity, and animations built on StatefulEffects.
  • Factories — ModalFactoryRegistry resolves a factory by request type. The factory loads the prefab, creates the Presenter, and releases everything in IModalInstance.Dispose().

Requirements

Unity 6 (6000.6), Addressables, URP.
Dependencies: UniTask, LitMotion, EventPrimitives, StatefulEffects.

Documentation

License

MIT

About

Clean Unity UI modal & dialog window system built with MVP and a pure C# engine-independent core. Supports queue/stack transitions, Addressables, UniTask

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages