Added PlayerList

This commit is contained in:
Jason Durand 2022-06-01 15:15:42 -04:00
parent 535d6c4e77
commit b19f150725
2 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,35 @@
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class PlayerList : MonoBehaviour {
HashSet<int> playerIds = new();
TMP_Text text;
void Awake() {
text = GetComponent<TMP_Text>();
text.text = "";
}
public void SetPlayerList(IEnumerable<int> ids) {
playerIds.Clear();
foreach (int id in ids)
playerIds.Add(id);
}
public void Connected(int id) {
playerIds.Add(id);
UpdateList();
}
public void Disconnected(int id) {
playerIds.Remove(id);
UpdateList();
}
void UpdateList() {
text.text = "";
foreach (int playerId in playerIds)
text.text += $"Player #{playerId}\n";
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8f4454c6a8ff1f5478829232f04817a5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: