Class UnityToastComponent
Lightweight, non-blocking notification ("toast"): shows a short message, holds it, and removes it,
without interrupting input the way a modal does.
Fully no-code to trigger: Show(string) is wirable from any UnityEvent (a Button's
onClick, a SignalReactionComponent response, an animation event…) with the message typed
straight into the inspector — so "when signal X happens, toast 'Saved!'" needs no script.
Namespace: Serenity.Ui.Infrastructure.Components.Toast
Assembly: Serenity.UnityUi.Infrastructure.dll
Syntax
public class UnityToastComponent : MonoBehaviour
Remarks
The visual is a prefab (any GameObject carrying a TMPro.TMP_Text) resolved as: the per-component
Serenity.Ui.Infrastructure.Components.Toast.UnityToastComponent.toastPrefab when assigned (explicit override), otherwise the active UI theme's
ToastTemplate (resolved once via the service locator and cached) — so a designer can theme all toasts
in one place and only override per scene when needed.
Animation lives entirely on the prefab. A theme that wants its toast animated gives its toast prefab an UnityEngine.Animator + controller exposing a bool Serenity.Ui.Infrastructure.Components.Toast.UnityToastComponent.showToggleParameter and a Serenity.Ui.Infrastructure.Components.Toast.UnityToastComponent.hideAnimationState state (the same convention as the modal). This component does not animate anything in code — it just toggles that parameter on to show and off to hide, then destroys the instance once the hide state has played. A theme whose prefab has no Animator simply appears and is removed after the hold with no animation. Timing uses UnityEngine.Time.unscaledDeltaTime so toasts work while paused.
Intentionally no Business IToast port: the Business-facing contract already exists as
ShowToastSignal dispatched through IEventDispatcherService
(the same signal/dispatcher abstraction used elsewhere), with UnityToastSignalReactionComponent
as the bridge. This component is purely the Unity-side renderer (prefab instantiation, uGUI sizing,
Animator-driven show/hide, coroutine lifecycle) behind that contract, re-authored per engine.
Constructors
UnityToastComponent()
Declaration
public UnityToastComponent()
Methods
Show(string)
Shows a toast carrying message (falls back to the default message when empty).
Declaration
public void Show(string message)
Parameters
| Type | Name | Description |
|---|---|---|
| string | message | The text to display. |
Show(string, bool)
Shows a toast carrying message, optionally treating it as a localization key.
Declaration
public void Show(string message, bool translate)
Parameters
| Type | Name | Description |
|---|---|---|
| string | message | The text to display. Falls back to the default message when empty. |
| bool | translate | When true and |
ShowDefault()
Shows a toast carrying the configured Serenity.Ui.Infrastructure.Components.Toast.UnityToastComponent.defaultMessage.
Declaration
public void ShowDefault()