Fix player components injection. Add lobby reloading when clients change

This commit is contained in:
2024-09-11 21:03:47 +02:00
parent 9250b7b5dd
commit e428d3a9f9
10 changed files with 284 additions and 86 deletions

View File

@@ -1,5 +1,6 @@
using HurricaneVR.Framework.Core.UI;
using Sirenix.OdinInspector;
using System.Collections.Generic;
using TMPro;
using Unity.Netcode;
using UnityEngine;
@@ -51,6 +52,8 @@ public class LobbyMenuUI : MonoBehaviour
private bool isConnected => gameManager.IsMultiplayer;
private IReadOnlyList<NetworkClient> networkClients = new List<NetworkClient>();
private void Start()
{
if (uiInput == null) return;
@@ -64,6 +67,12 @@ public class LobbyMenuUI : MonoBehaviour
gameManager.OnConnected.AddListener(() => UpdateUI());
gameManager.OnDisconnected.AddListener(() => UpdateUI());
gameManager.OnClientsChanged.AddListener((clients) =>
{
networkClients = clients;
UpdateUI();
});
UpdateUI();
}
@@ -73,6 +82,28 @@ public class LobbyMenuUI : MonoBehaviour
connected.SetActive(isConnected);
joinButton.interactable = true;
hostButton.interactable = true;
for (int i = 0; i < playerItems.Length; i++)
{
var item = playerItems[i];
if (i > networkClients.Count -1)
{
item.Setup(null);
}
else
{
var client = networkClients[i];
var playerInfo = new PlayerInfo()
{
Name = client.ClientId.ToString(),
isLocalPlayer = client.ClientId == gameManager.LocalClient.ClientId
};
item.Setup(playerInfo);
}
}
}
private void JoinClicked()