51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace UI
|
|
{
|
|
public class LobbyController : MonoBehaviour
|
|
{
|
|
private UIDocument _doc;
|
|
private Button _btnLeave;
|
|
private Button _btnStart;
|
|
private ScrollView _playerList;
|
|
|
|
private void OnEnable()
|
|
{
|
|
_doc = GetComponent<UIDocument>();
|
|
var root = _doc.rootVisualElement;
|
|
|
|
// BINDING: Tìm element theo tên (Name) đã đặt trong UXML
|
|
_btnLeave = root.Q<Button>("btn-leave");
|
|
_btnStart = root.Q<Button>("btn-start");
|
|
_playerList = root.Q<ScrollView>("player-list");
|
|
|
|
// ĐĂNG KÝ SỰ KIỆN:
|
|
if (_btnLeave != null)
|
|
_btnLeave.clicked += OnLeaveClicked;
|
|
|
|
if (_btnStart != null)
|
|
_btnStart.clicked += OnStartClicked;
|
|
}
|
|
|
|
private void OnLeaveClicked()
|
|
{
|
|
Debug.Log("User clicked LEAVE room!");
|
|
UIManager.Instance.ShowScreen("MainMenu");
|
|
}
|
|
|
|
private void OnStartClicked()
|
|
{
|
|
Debug.Log("Host clicked START GAME!");
|
|
UIManager.Instance.ShowScreen("HUD"); // Chuyển vào HUD khi game bắt đầu
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
// Hủy đăng ký để tránh memory leak
|
|
if (_btnLeave != null) _btnLeave.clicked -= OnLeaveClicked;
|
|
if (_btnStart != null) _btnStart.clicked -= OnStartClicked;
|
|
}
|
|
}
|
|
}
|