47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using UdonSharp;
|
|
using UnityEngine;
|
|
using UnityEngine.SocialPlatforms.Impl;
|
|
using UnityEngine.UI;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon;
|
|
|
|
public class ScoreboardRowSpawner : Scoreboard
|
|
{
|
|
public GameObject rowPrefab;
|
|
public Transform rowContainer;
|
|
|
|
public override void UpdateScoreboard()
|
|
{
|
|
for (int i = rowContainer.childCount - 1; i >= 0; i--)
|
|
{
|
|
Destroy(rowContainer.GetChild(i).gameObject);
|
|
}
|
|
|
|
VRCPlayerApi[] players = playerManager.GetCurrentPlayers();
|
|
for (int i = 0; i < players.Length; i++)
|
|
{
|
|
VRCPlayerApi player = players[i];
|
|
GameObject newRow = Instantiate(rowPrefab, rowContainer);
|
|
|
|
TMPro.TMP_Text[] textComponents = newRow.GetComponentsInChildren<TMPro.TMP_Text>();
|
|
|
|
if (textComponents.Length > 0)
|
|
{
|
|
textComponents[0].text = player.displayName;
|
|
}
|
|
|
|
if (textComponents.Length > 1)
|
|
{
|
|
textComponents[1].text = playerManager.GetScore(player.playerId).ToString();
|
|
}
|
|
|
|
Image backgroundComponent = newRow.GetComponent<Image>();
|
|
if (backgroundComponent != null)
|
|
{
|
|
backgroundComponent.color = playerManager.GetTeam(player.playerId) == "red" ?
|
|
new Color(1f, 0f, 0f, 0.5f) : playerManager.GetTeam(player.playerId) == "blue" ? new Color(0f, 0f, 1f, 0.5f) : new Color(0.5f, 0.5f, 0.5f, 0.5f);
|
|
}
|
|
}
|
|
}
|
|
}
|