using System; using TMPro; using UnityEngine; using UnityEngine.UI; namespace HotUpdate.UI { /// /// UI_ConfirmDialog:公告 / 维护 / 通用确认。 /// public sealed class ConfirmDialogView : MonoBehaviour { public const string PrefabName = "UI_ConfirmDialog"; TextMeshProUGUI _title; TextMeshProUGUI _message; Button _ok; Button _cancel; Button _close; Action _onOk; Action _onCancel; public void Bind() { _title = FindTmp("Txt_Title"); _message = FindTmp("Txt_Message"); _ok = FindBtn("Btn_Ok"); _cancel = FindBtn("Btn_Cancel"); _close = FindBtn("Btn_Close"); Wire(_ok, () => { _onOk?.Invoke(); Hide(); }); Wire(_cancel, () => { _onCancel?.Invoke(); Hide(); }); Wire(_close, () => { _onCancel?.Invoke(); Hide(); }); } public void Show( string title, string message, Action onOk = null, Action onCancel = null, bool showCancel = false) { if (_title != null) _title.text = title ?? string.Empty; if (_message != null) _message.text = message ?? string.Empty; _onOk = onOk; _onCancel = onCancel; if (_cancel != null) _cancel.gameObject.SetActive(showCancel); gameObject.SetActive(true); } public void Hide() { gameObject.SetActive(false); } static void Wire(Button btn, Action action) { if (btn == null) return; btn.onClick.RemoveAllListeners(); btn.onClick.AddListener(() => action?.Invoke()); } TextMeshProUGUI FindTmp(string name) { foreach (var c in GetComponentsInChildren(true)) if (c.name == name) return c; return null; } Button FindBtn(string name) { foreach (var c in GetComponentsInChildren