Introduce UiManager/MainHUD prefab flow, strengthen GameNet/WsClient, and add AIServer maintenance endpoint support. Co-authored-by: Cursor <cursoragent@cursor.com>
72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace HotUpdate.UI
|
|
{
|
|
/// <summary>
|
|
/// UI_MainHUD 运行时绑定。
|
|
/// </summary>
|
|
public sealed class MainHudView : MonoBehaviour
|
|
{
|
|
public const string PrefabName = "UI_MainHUD";
|
|
|
|
TextMeshProUGUI _status;
|
|
TextMeshProUGUI _pid;
|
|
GameObject _reconnectPanel;
|
|
TextMeshProUGUI _reconnectText;
|
|
Button _reconnectBtn;
|
|
|
|
public event Action OnReconnectClicked;
|
|
|
|
public void Bind()
|
|
{
|
|
_status = FindTmp("Txt_Status");
|
|
_pid = FindTmp("Txt_Pid");
|
|
var panel = transform.Find("Panel_Reconnect");
|
|
_reconnectPanel = panel != null ? panel.gameObject : null;
|
|
_reconnectText = FindTmp("Txt_Reconnect");
|
|
var btnTf = transform.Find("Panel_Reconnect/Btn_Reconnect");
|
|
_reconnectBtn = btnTf != null ? btnTf.GetComponent<Button>() : null;
|
|
if (_reconnectBtn != null)
|
|
{
|
|
_reconnectBtn.onClick.RemoveAllListeners();
|
|
_reconnectBtn.onClick.AddListener(() => OnReconnectClicked?.Invoke());
|
|
}
|
|
ShowReconnect(false);
|
|
}
|
|
|
|
public void SetStatus(string text)
|
|
{
|
|
if (_status != null) _status.text = text ?? string.Empty;
|
|
}
|
|
|
|
public void SetPid(long pid)
|
|
{
|
|
if (_pid != null) _pid.text = pid > 0 ? $"pid={pid}" : "pid=-";
|
|
}
|
|
|
|
public void ShowReconnect(bool visible, string message = null)
|
|
{
|
|
if (_reconnectPanel != null) _reconnectPanel.SetActive(visible);
|
|
if (visible && _reconnectText != null && !string.IsNullOrEmpty(message))
|
|
_reconnectText.text = message;
|
|
}
|
|
|
|
TextMeshProUGUI FindTmp(string path)
|
|
{
|
|
var t = transform.Find(path);
|
|
if (t == null)
|
|
{
|
|
// 深层查找
|
|
var all = GetComponentsInChildren<TextMeshProUGUI>(true);
|
|
foreach (var c in all)
|
|
if (c.name == path) return c;
|
|
return null;
|
|
}
|
|
return t.GetComponent<TextMeshProUGUI>();
|
|
}
|
|
}
|
|
}
|