CarmenSandiego/Assets/UdonSharp/PlayerPodium.cs
Jamie Greunbaum de0a866e6d - Lightning round is essentially complete, with scoring fully implemented.
- Podium name tag can no longer be blocked by score card.
- Choice cards don't display text for anyone but the owner until locked in.
- Minor corrections to the ACME Crimenet logo.
2025-06-04 19:28:17 -04:00

147 lines
2.8 KiB
C#

using UdonSharp;
using UnityEngine;
using TMPro;
using VRC.SDKBase;
using VRC.SDK3.UdonNetworkCalling;
using VRC.Udon.Common.Interfaces;
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
public class PlayerPodium : UdonSharpBehaviour
{
public int PlayerNumber = 0;
public GameManager GameManager;
[UdonSynced, FieldChangeCallback(nameof(PlayerName))] private string _PlayerName = "Player";
[UdonSynced] private int _PlayerID = -1;
[UdonSynced, FieldChangeCallback(nameof(PlayerScore))] private int _PlayerScore = 50;
[SerializeField] private ChoiceCardGroup _ChoiceCards;
[SerializeField] private Buzzer _Buzzer;
[Header("Effects")]
[SerializeField] private GameObject _BuzzedInEffect;
[SerializeField] private TextMeshProUGUI _Nameplate;
[SerializeField] private TextMeshProUGUI _Scorecard;
void Start()
{
PlayerName = "Player " + PlayerNumber;
}
public void SetPlayerName()
{
if (_PlayerID != -1)
{
return;
}
Networking.SetOwner(Networking.LocalPlayer, gameObject);
Networking.SetOwner(Networking.LocalPlayer, _ChoiceCards.gameObject);
Networking.SetOwner(Networking.LocalPlayer, _Buzzer.gameObject);
PlayerName = Networking.LocalPlayer.displayName;
_PlayerID = Networking.LocalPlayer.playerId;
RequestSerialization();
}
public int GetPlayerID() { return _PlayerID; }
[NetworkCallable]
public void DecreaseScoreBy5()
{
PlayerScore -= 5;
}
[NetworkCallable]
public void IncreaseScoreBy5()
{
PlayerScore += 5;
}
[NetworkCallable]
public void IncreaseScoreBy10()
{
PlayerScore += 10;
}
[NetworkCallable]
public void EnableChoiceCards(bool Enable)
{
_ChoiceCards.gameObject.SetActive(Enable);
_ChoiceCards.ResetCards();
NetworkCalling.SendCustomNetworkEvent(
(IUdonEventReceiver)_ChoiceCards,
NetworkEventTarget.Owner,
"MakeChoiceTextVisible");
}
[NetworkCallable]
public void SetCardChoices(string[] Choices, int[] Indices)
{
_ChoiceCards.SetChoices(Choices, Indices);
}
[NetworkCallable]
public void LockInChoice()
{
_ChoiceCards.LockInChoice();
NetworkCalling.SendCustomNetworkEvent(
(IUdonEventReceiver)_ChoiceCards,
NetworkEventTarget.All,
"MakeChoiceTextVisible");
}
[NetworkCallable]
public void VerifyMultipleChoiceResponse(int CorrectResponse)
{
if (_ChoiceCards.GetSelectedChoice() == CorrectResponse)
{
IncreaseScoreBy10();
}
}
[NetworkCallable]
public void EnableBuzzer(bool Enable)
{
_Buzzer.gameObject.SetActive(Enable);
}
[NetworkCallable]
public void EnableBuzzInEffect(bool Enable)
{
_BuzzedInEffect.SetActive(Enable);
}
public string PlayerName
{
set
{
_PlayerName = value;
_Nameplate.text = value;
}
get => _PlayerName;
}
public int PlayerScore
{
set
{
_PlayerScore = value;
_Scorecard.text = PlayerScore.ToString();
RequestSerialization();
}
get => _PlayerScore;
}
}