Files
QuizzinMk5.1/Assets/Quiz/Scripts/Debug/DebugView.cs
2025-11-18 00:32:07 +00:00

57 lines
1.7 KiB
C#

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
public class DebugView : UdonSharpBehaviour
{
[SerializeField] private DebugPlayerRow playerRowPrefab;
[SerializeField] private PlayerManager playerManager;
[SerializeField] private GameObject rowContainer;
private DebugPlayerRow[] playerRows = new DebugPlayerRow[0];
public void UpdatePlayerRows()
{
if (playerManager == null || rowContainer == null || playerRowPrefab == 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 DebugPlayerRow[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(playerRowPrefab.gameObject);
rowObj.transform.SetParent(rowContainer.transform, false);
DebugPlayerRow row = rowObj.GetComponent<DebugPlayerRow>();
row.player = player;
row.playerManager = playerManager;
// Build player info string
int playerId = player.playerId;
string playerName = player.displayName;
int score = playerManager.GetScore(playerId);
string team = playerManager.GetTeam(playerId);
string info = playerName + " | Team: " + team + " | Score: " + score;
row.SetPlayerInfo(info);
playerRows[i] = row;
}
}
}