using System; using DG.Tweening; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class MessageBoxDialog : MonoBehaviour { public const float ANIMATION_DURATION = 0.25f; /// Above game/menu/loader canvases; below reconnect (500). const int OverlaySortingOrder = 400; public static MessageBoxDialog instance; public static bool IsAvailable => instance != null; public RectTransform dimmer; public RectTransform basicMessageBox; [Header("MessageBox")] public RectTransform messageBox; public TMP_Text txtTitle, txtMessage; public Button btnOk, btnYes, btnNo; Image dimmerImg; TMP_Text basicMessageText; Action onYesOrNo; Sequence showHideSequence; Canvas overlayCanvas; void Awake() { if (instance != null && instance != this) { Destroy(gameObject); return; } instance = this; DontDestroyOnLoad(gameObject); overlayCanvas = GetComponent(); if (overlayCanvas != null) overlayCanvas.sortingOrder = OverlaySortingOrder; if (dimmer != null) dimmerImg = dimmer.GetComponent(); if (basicMessageBox != null) basicMessageText = basicMessageBox.GetComponentInChildren(); } void OnEnable() { if (instance != this) return; SceneManager.sceneLoaded += OnSceneLoaded; } void OnDisable() { if (instance != this) return; SceneManager.sceneLoaded -= OnSceneLoaded; } void OnSceneLoaded(Scene scene, LoadSceneMode mode) { transform.SetAsLastSibling(); } public static void ShowBasic(string title) { if (instance == null) { Debug.LogWarning("MessageBoxDialog missing: " + title); return; } instance.ShowMessageBox(title); } public static void Show(string title, string message, Action onResult = null) { if (instance == null) { Debug.LogWarning("MessageBoxDialog missing: " + title); return; } instance.ShowMessageBox(title, message, onResult); } void OnDestroy() { KillTweens(); if (instance == this) instance = null; } void Start() { Button basicButton = basicMessageBox != null ? basicMessageBox.GetComponent