Added basic lobby
This commit is contained in:
36
Assets/Scripts/Lobby/LobbyClientDisplayManager.cs
Normal file
36
Assets/Scripts/Lobby/LobbyClientDisplayManager.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using PashaBibko.PenguinChase.Network;
|
||||
using UnityEngine;
|
||||
|
||||
namespace PashaBibko.PenguinChase.Lobby
|
||||
{
|
||||
public class LobbyClientDisplayManager : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private GameObject ClientDisplayPrefab;
|
||||
[SerializeField] private GameObject ClientDisplayParent;
|
||||
|
||||
private int mCachedClientCount = -1; // Forces a refresh on initial load
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Checks if the client count has changed since last update
|
||||
if (mCachedClientCount != GameNetworkClient.ConnectedClientCount)
|
||||
{
|
||||
// Clears all old client displays
|
||||
foreach (Transform child in ClientDisplayParent.transform)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
// Creates new objects for each client
|
||||
GameNetworkClient[] clients = GameNetworkClient.ConnectedClients;
|
||||
foreach (GameNetworkClient client in clients)
|
||||
{
|
||||
GameObject go = Instantiate(ClientDisplayPrefab, ClientDisplayParent.transform);
|
||||
LobbyClientDisplay display = go.GetComponent<LobbyClientDisplay>();
|
||||
display.SetText(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user