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/awaiton 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
Addressablesin 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.
// 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);| 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. |
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/Pushqueue and runs all transitions sequentially in a single loop. - ModalWindow — owns one window's lifecycle and
ModalStatus; routes close requests fromModalHandle,Presenter, and service through one path (first reason wins). - MVP —
Model(plain data, no reference toModals),Presenter(behavior,IsBusy, close requests),View(UI only). - ModalStage / ModalShell —
Active,Transition, andPassivelayers, interactivity, and animations built on StatefulEffects. - Factories —
ModalFactoryRegistryresolves a factory by request type. The factory loads the prefab, creates thePresenter, and releases everything inIModalInstance.Dispose().
Unity 6 (6000.6), Addressables, URP.
Dependencies: UniTask, LitMotion, EventPrimitives, StatefulEffects.
- API and integration guide (Russian):
Assets/Modals/README.md - Internals and invariants (Russian):
Assets/Modals/ARCHITECTURE.md
MIT