Files
AIGame/AIClient/Assets/HotUpdate/Scripts/UI/ConfirmDialogView.cs
T
udxandCursor c94b8fefeb Add MainHUD gameplay UI, net handshake updates, and server maintenance mode.
Introduce UiManager/MainHUD prefab flow, strengthen GameNet/WsClient, and add AIServer maintenance endpoint support.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-21 17:34:42 +08:00

78 lines
2.2 KiB
C#

using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace HotUpdate.UI
{
/// <summary>
/// UI_ConfirmDialog:公告 / 维护 / 通用确认。
/// </summary>
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<TextMeshProUGUI>(true))
if (c.name == name) return c;
return null;
}
Button FindBtn(string name)
{
foreach (var c in GetComponentsInChildren<Button>(true))
if (c.name == name) return c;
return null;
}
}
}