2026-04-28 19:04:09 +07:00
|
|
|
#if false
|
|
|
|
|
using System.Collections.Generic;
|
2026-04-11 18:13:40 +07:00
|
|
|
using Fusion;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
public class _LobbyManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public GameObject lobbyPanel;
|
2026-04-27 15:48:01 +07:00
|
|
|
|
2026-04-11 18:13:40 +07:00
|
|
|
|
|
|
|
|
public _BasicSpawner spawner;
|
|
|
|
|
|
|
|
|
|
[Header("Character Selection")] public TMP_InputField playerNameInput;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Header("Room List")] public GameObject roomListParent;
|
|
|
|
|
public GameObject roomListItemPrefab;
|
|
|
|
|
public TMP_InputField roomNameInput;
|
|
|
|
|
|
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
|
|
|
async void Start()
|
|
|
|
|
{
|
|
|
|
|
lobbyPanel.SetActive(false);
|
2026-04-23 08:56:35 +07:00
|
|
|
|
2026-04-11 18:13:40 +07:00
|
|
|
|
|
|
|
|
spawner = FindFirstObjectByType<_BasicSpawner>();
|
|
|
|
|
await spawner.StartLobby();
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 08:56:35 +07:00
|
|
|
|
2026-04-11 18:13:40 +07:00
|
|
|
|
|
|
|
|
public void OnNextButton()
|
|
|
|
|
{
|
|
|
|
|
var playerName = playerNameInput.text;
|
|
|
|
|
if (string.IsNullOrEmpty(playerName))
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("Player name cannot be empty!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// tạo 1 player _profile tạm thời, sau này sẽ gửi lên server để tạo player object
|
|
|
|
|
var _profile = new _PlayerProfile()
|
|
|
|
|
{
|
|
|
|
|
Name = playerName,
|
2026-04-23 08:56:35 +07:00
|
|
|
|
2026-04-11 18:13:40 +07:00
|
|
|
};
|
|
|
|
|
spawner.SetLocalPlayerProfile(_profile);
|
|
|
|
|
// đưa lên host để tạo player object, ở đây tạm thời chỉ log ra console
|
2026-04-23 08:56:35 +07:00
|
|
|
Debug.Log($"Player Name: {_profile.Name}, Class: {_profile.Role}");
|
2026-04-11 18:13:40 +07:00
|
|
|
// chuyển sang lobby panel
|
2026-04-27 15:48:01 +07:00
|
|
|
|
2026-04-11 18:13:40 +07:00
|
|
|
lobbyPanel.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// hiển thị danh sách phòng
|
|
|
|
|
public void DisplayRoomList(List<SessionInfo> sessions)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"Received {sessions.Count} sessions from lobby");
|
|
|
|
|
// clear danh sách cũ
|
|
|
|
|
foreach (Transform child in roomListParent.transform)
|
|
|
|
|
{
|
|
|
|
|
Destroy(child.gameObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sessions.Count == 0) return;
|
|
|
|
|
|
|
|
|
|
// tạo item mới cho mỗi phòng
|
|
|
|
|
foreach (var session in sessions)
|
|
|
|
|
{
|
|
|
|
|
var item = Instantiate(roomListItemPrefab, roomListParent.transform);
|
|
|
|
|
var text = item.GetComponentInChildren<TextMeshProUGUI>();
|
|
|
|
|
text.text = $"{session.Name} ({session.PlayerCount}/{session.MaxPlayers})";
|
|
|
|
|
var button = item.GetComponentInChildren<Button>();
|
|
|
|
|
button.onClick.AddListener(() => OnJoinRoom(session.Name));
|
|
|
|
|
item.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async void OnJoinRoom(string sessionName)
|
|
|
|
|
{
|
|
|
|
|
await spawner.StartClient(sessionName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async void OnCreateRoomButton()
|
|
|
|
|
{
|
|
|
|
|
var roomName = roomNameInput.text;
|
|
|
|
|
if (string.IsNullOrEmpty(roomName))
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("Room name cannot be empty!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// tạo phòng mới với tên đã nhập
|
|
|
|
|
await spawner.StartHost(roomName, SceneRef.FromIndex(1));
|
|
|
|
|
}
|
2026-04-28 19:04:09 +07:00
|
|
|
}
|
|
|
|
|
#endif
|