58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using UnityEngine.PlayerLoop;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon;
|
|
|
|
public class TabletScoreboard : Scoreboard
|
|
{
|
|
public TabletRow tabletRowPrefab;
|
|
|
|
private TabletRow[] playerRows = new TabletRow[0];
|
|
|
|
|
|
public override void UpdateScoreboard()
|
|
{
|
|
UpdatePlayerRows();
|
|
}
|
|
|
|
public void UpdatePlayerRows()
|
|
{
|
|
if (playerManager == null || tabletRowPrefab == null) return;
|
|
|
|
// Clear existing rows
|
|
for (int i = 0; i < playerRows.Length; i++)
|
|
{
|
|
if (playerRows[i] != null)
|
|
{
|
|
Destroy(playerRows[i].gameObject);
|
|
}
|
|
}
|
|
|
|
// Get current players
|
|
VRCPlayerApi[] players = playerManager.GetCurrentPlayers();
|
|
playerRows = new TabletRow[players.Length];
|
|
|
|
// Create a row for each player
|
|
for (int i = 0; i < players.Length; i++)
|
|
{
|
|
VRCPlayerApi player = players[i];
|
|
if (player == null) continue;
|
|
|
|
GameObject rowObj = Instantiate(tabletRowPrefab.gameObject);
|
|
rowObj.transform.SetParent(this.transform, false);
|
|
TabletRow row = rowObj.GetComponent<TabletRow>();
|
|
row.player = player;
|
|
row.playerManager = playerManager;
|
|
|
|
// Set player name
|
|
row.SetPlayerName(player.displayName);
|
|
string teamColor = playerManager.GetTeam(player.playerId);
|
|
row.SetBackgroundColor(teamColor == "red" ? Color.red : teamColor == "blue" ? Color.blue : Color.grey);
|
|
|
|
playerRows[i] = row;
|
|
}
|
|
}
|
|
}
|