ToastManager
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
The ToastManager is a singleton utility component within the MultiSet SDK responsible for displaying temporary, non-interactive messages on the screen. It is used throughout the SDK to provide users with immediate feedback, such as "Localization Success" or "Network Error".
This manager controls a UI element, typically consisting of a CanvasGroup and a Text component, to create a "toast" or "alert" message. It makes the message fade in, stay visible for a short period, and then fade out automatically. As a singleton, it can be easily accessed from any other script in your project using ToastManager.Instance without needing a direct reference.
This section details the publicly accessible fields of the ToastManager that you can configure in the Unity Editor.
Property
Type
Description
Instance
static ToastManager
The static singleton instance of the ToastManager. This provides a global access point to the manager's functionality.
toastText
Text
The Unity UI Text component where the message content will be displayed. This should be a child of the GameObject that has the CanvasGroup.
canvasGroup
CanvasGroup
The CanvasGroup component that controls the alpha (transparency) and raycast blocking of the entire toast UI element. This is used to fade the message in and out.
fadeDuration
float
The duration in seconds that the fade-in and fade-out animations will take. The default value is 0.5f.
displayDuration
float
The duration in seconds that the toast message will remain fully visible on the screen after fading in and before it starts to fade out. The default value is 2f.
This section describes the publicly accessible methods of the ToastManager.
ShowToast()
Displays a toast message on the screen.
public void ShowToast(string message)
Description When you call this method, the provided message string is assigned to the toastText component, and the toast UI begins its fade-in and fade-out sequence. The entire animation is handled automatically.
ToastManager.Instance.ShowToast("Your action was successful!");
ShowAlert()
Displays an alert message on the screen.
public void ShowAlert(string alertText)
Description This method is functionally identical to ShowToast(). It takes a string alertText and displays it using the same fade-in and fade-out animation. It is provided as an alternative name for semantic clarity in your code.
ToastManager.Instance.ShowAlert("Warning: Low battery.");