Update
This commit is contained in:
50
Assets/Scripts/UI/LobbyController.cs
Normal file
50
Assets/Scripts/UI/LobbyController.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user