using System; using TMPro; using UnityEngine; using UnityEngine.UI; namespace XGame { // 匹配大厅运行时控制器。沿用 AuthRegisterLoginController 模式: // 按节点名缓存控件、克隆模板行、回调 Lua。只传基本类型跨 XLua。 public class GameLobbyController : MonoBehaviour { private Transform listGames; private GameObject itemTemplate; private TMP_Text statusText; private RectTransform panelLobby; private RectTransform collapseButtonRect; private Button collapseButton; private TMP_Text collapseText; private GameObject titleObject; private GameObject scrollObject; private Vector2 expandedPanelSize; private Vector2 expandedButtonPosition; private bool hasCollapseMetrics; private bool leftLayoutApplied; private bool rootMatchButtonBound; private bool collapsed; private string currentStatus = string.Empty; private string luaModule = "client/baseworld"; public Action OnMatch; private const float LobbyPanelWidth = 520f; private const float LobbyPanelHeight = 296f; private const float LobbyPanelLeft = 24f; private const float LobbyPanelTop = -24f; private const float CollapsedPanelWidth = 56f; private void Awake() { CacheControls(); } public void Bind(string module) { if (!string.IsNullOrEmpty(module)) { luaModule = module; } } // 清空旧克隆行 public void BeginGames() { CacheControls(); if (listGames == null) { return; } for (int i = listGames.childCount - 1; i >= 0; i--) { Transform child = listGames.GetChild(i); if (itemTemplate != null && child == itemTemplate.transform) { continue; } Destroy(child.gameObject); } } // 逐行追加。gameId 按行捕获用于点击回调 public void AddGame(string gameId, string name, string players) { CacheControls(); if (itemTemplate == null || listGames == null) { return; } GameObject row = Instantiate(itemTemplate, listGames); row.name = "Item_Game_" + gameId; row.SetActive(true); SetChildText(row.transform, "Txt_GameName", name); SetChildText(row.transform, "Txt_Players", players); Transform btnTf = row.transform.FindTransform("Btn_Match"); if (btnTf != null) { Button btn = btnTf.GetComponent