92 lines
2.8 KiB
C#
92 lines
2.8 KiB
C#
using UdonSharp;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using VRC.SDK3.UdonNetworkCalling;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon;
|
|
|
|
public class NoPointsPlayerScreen : UdonSharpBehaviour
|
|
{
|
|
public VRCPlayerApi claimedPlayer = null;
|
|
public TMPro.TextMeshProUGUI playerNameDisplay;
|
|
public TMPro.TextMeshProUGUI claimButtonText;
|
|
public TMPro.TMP_InputField suggestionInputField;
|
|
public NoPointsDeskManager deskManager;
|
|
public GameObject inputRow;
|
|
public GameObject suggestionDisplay;
|
|
public GameObject suggestionPrefab;
|
|
[UdonSynced] private string playerNameText = "Unclaimed";
|
|
[UdonSynced] public int claimedPlayerId = 0;
|
|
|
|
public void ClaimScreen()
|
|
{
|
|
VRCPlayerApi player = Networking.LocalPlayer;
|
|
claimedPlayer = player;
|
|
claimedPlayerId = player.playerId;
|
|
playerNameText = player.displayName;
|
|
inputRow.SetActive(true);
|
|
}
|
|
|
|
[NetworkCallable]
|
|
public void AddSuggestion(string suggestion)
|
|
{
|
|
GameObject newSuggestionObj = Instantiate(suggestionPrefab);
|
|
TMPro.TextMeshProUGUI newSuggestionText = newSuggestionObj.GetComponent<TMPro.TextMeshProUGUI>();
|
|
newSuggestionText.text = suggestion;
|
|
newSuggestionObj.transform.SetParent(suggestionDisplay.transform, false);
|
|
newSuggestionObj.transform.SetSiblingIndex(0);
|
|
}
|
|
|
|
public void HandleClaimButtonPress()
|
|
{
|
|
if (!Networking.IsOwner(gameObject))
|
|
{
|
|
Networking.SetOwner(Networking.LocalPlayer, gameObject);
|
|
}
|
|
|
|
VRCPlayerApi localPlayer = Networking.LocalPlayer;
|
|
if (claimedPlayerId == 0)
|
|
{
|
|
ClaimScreen();
|
|
playerNameDisplay.text = playerNameText;
|
|
claimButtonText.text = "Unclaim Screen";
|
|
}
|
|
else if (claimedPlayerId == localPlayer.playerId)
|
|
{
|
|
claimedPlayer = null;
|
|
claimedPlayerId = 0;
|
|
playerNameText = "Unclaimed";
|
|
playerNameDisplay.text = playerNameText;
|
|
claimButtonText.text = "Claim Screen";
|
|
inputRow.SetActive(false);
|
|
}
|
|
RequestSerialization();
|
|
}
|
|
|
|
public void HandleSendButtonPress()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(suggestionInputField.text))
|
|
return;
|
|
|
|
deskManager.SendSuggestion(Networking.LocalPlayer.displayName + " suggests: " + suggestionInputField.text);
|
|
suggestionInputField.text = "";
|
|
}
|
|
|
|
public override void OnDeserialization()
|
|
{
|
|
playerNameDisplay.text = playerNameText;
|
|
if (claimedPlayerId == 0)
|
|
{
|
|
claimButtonText.text = "Claim Screen";
|
|
}
|
|
else if (claimedPlayerId == Networking.LocalPlayer.playerId)
|
|
{
|
|
claimButtonText.text = "Unclaim Screen";
|
|
}
|
|
else
|
|
{
|
|
claimButtonText.text = "Screen Claimed";
|
|
}
|
|
}
|
|
}
|