Organize custom scripts and Shared under Assets/Scripts, and delete assembly definition files
This commit is contained in:
101
Assets/Scripts/Baba_yaga/Duy/LobbyManager.cs
Normal file
101
Assets/Scripts/Baba_yaga/Duy/LobbyManager.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
#if false
|
||||
using System.Collections.Generic;
|
||||
using Fusion;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class _LobbyManager : MonoBehaviour
|
||||
{
|
||||
public GameObject lobbyPanel;
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
spawner = FindFirstObjectByType<_BasicSpawner>();
|
||||
await spawner.StartLobby();
|
||||
}
|
||||
|
||||
|
||||
|
||||
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,
|
||||
|
||||
};
|
||||
spawner.SetLocalPlayerProfile(_profile);
|
||||
// đưa lên host để tạo player object, ở đây tạm thời chỉ log ra console
|
||||
Debug.Log($"Player Name: {_profile.Name}, Class: {_profile.Role}");
|
||||
// chuyển sang lobby panel
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
2
Assets/Scripts/Baba_yaga/Duy/LobbyManager.cs.meta
Normal file
2
Assets/Scripts/Baba_yaga/Duy/LobbyManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 258164a5e282e34489a3c62c443c22f0
|
||||
Reference in New Issue
Block a user