diff --git a/Assets/Scripts/PlayerList.cs b/Assets/Scripts/PlayerList.cs new file mode 100644 index 0000000..e2153d0 --- /dev/null +++ b/Assets/Scripts/PlayerList.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using TMPro; +using UnityEngine; + +public class PlayerList : MonoBehaviour { + HashSet playerIds = new(); + TMP_Text text; + + void Awake() { + text = GetComponent(); + text.text = ""; + } + + public void SetPlayerList(IEnumerable 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"; + } +} \ No newline at end of file diff --git a/Assets/Scripts/PlayerList.cs.meta b/Assets/Scripts/PlayerList.cs.meta new file mode 100644 index 0000000..4cf6775 --- /dev/null +++ b/Assets/Scripts/PlayerList.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8f4454c6a8ff1f5478829232f04817a5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: