mirror of
https://github.com/ConjureETS/ProjectClubCore.git
synced 2026-03-24 01:20:59 +00:00
35 lines
632 B
C#
35 lines
632 B
C#
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";
|
|
}
|
|
} |