Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs-unity.molca.id/llms.txt

Use this file to discover all available pages before exploring further.

File: Assets/_Molca/_Core/Modals/ModalManager.cs
Type: RuntimeSubsystem (child of RuntimeManager prefab)

When to use

Use ModalManager for built-in modal types (message toasts, confirmation dialogs, loading overlays). For product-specific or complex modals (text input, selection, progress with custom UI), see Shared modals.

Role

Shows informational messages, confirmations, loading overlays, and ShowModal<T> for custom modal types. Prefabs and canvas wiring are assigned on the subsystem component in the Inspector.

Code

using Molca.Modals;
using UnityEngine;

public class ScoreReporter : MonoBehaviour
{
    public void ShowResult(string text)
    {
        ModalManager.Instance.AddMessage(text, ModalManager.MessageType.Default, 5f);
    }
}
Use ModalManager.Instance only after RuntimeManager has created the subsystem (e.g. after await RuntimeManager.WaitForInitialization()). Loading overlays and typed modals use other APIs on the same class.

API Reference

MethodSignatureDescription
ShowModal<T>T ShowModal<T>(bool closeOthers = true) where T : ComponentShow a registered modal prefab of type T; returns the instantiated component
HideModal<T>void HideModal<T>() where T : ComponentHide the currently active modal of type T
RegisterModalvoid RegisterModal(GameObject prefab)Register a modal prefab at runtime for use with ShowModal<T>
UnregisterModalvoid UnregisterModal(Type modalType)Unregister a previously registered modal type
AddMessagevoid AddMessage(string message, MessageType type, float duration)Display a toast message with specified type and auto-close duration
ShowConfirmationvoid ShowConfirmation(string title, string message, Action onConfirm, Action onCancel = null)Show a confirmation dialog with confirm/cancel callbacks
ShowLoadingvoid ShowLoading(string message = null)Display a loading overlay with optional message
HideLoadingvoid HideLoading()Hide the currently active loading overlay

Troubleshooting

  • Modal does not appear: confirm ModalManager.Instance is not null — the subsystem must exist on the RuntimeManager prefab and runtime must be initialized.
  • Modal appears behind other UI: check canvas sort order; ModalManager typically uses a high-priority canvas.
  • ShowModal<T> returns null: ensure the prefab for type T is registered in the ModalManager component’s prefab list in the Inspector.

Unity Editor

Modal Manager Inspector