Files
BABA_YAGA/Assets/Scripts/UI/LobbyController.cs
2026-04-26 04:39:59 +07:00

49 lines
1.3 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()
{
UIManager.Instance.GoBack();
}
private void OnStartClicked()
{
UIManager.Instance.ShowScreen("Lounge");
}
private void OnDisable()
{
// Hủy đăng ký để tránh memory leak
if (_btnLeave != null) _btnLeave.clicked -= OnLeaveClicked;
if (_btnStart != null) _btnStart.clicked -= OnStartClicked;
}
}
}