171 lines
3.7 KiB
C#
171 lines
3.7 KiB
C#
|
|
using TMPro;
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using VRC.SDK3.Components;
|
|
using VRC.SDK3.Data;
|
|
using VRC.SDK3.UdonNetworkCalling;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon.Common.Interfaces;
|
|
|
|
|
|
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
|
|
public class ChoiceCardGroup : UdonSharpBehaviour
|
|
{
|
|
[SerializeField] private PlayerPodium _Podium;
|
|
[SerializeField] private ChoiceCard[] _ChoiceCards;
|
|
[SerializeField] private TextMeshProUGUI[] _ChoiceCardText;
|
|
|
|
[SerializeField] private GameObject _PCCardHeldPosition;
|
|
[SerializeField] private Animator _PCCardAnimator;
|
|
|
|
[UdonSynced] private int _SelectedChoice = -1;
|
|
|
|
|
|
void Start()
|
|
{
|
|
for (int i = 0; i < _ChoiceCards.Length; i++)
|
|
{
|
|
ChoiceCard Card = _ChoiceCards[i];
|
|
|
|
Card.SetCardGroup(this);
|
|
}
|
|
}
|
|
|
|
[NetworkCallable]
|
|
public void ChoiceCardPickedUp(int ChoiceNumber)
|
|
{
|
|
_SelectedChoice = ChoiceNumber;
|
|
}
|
|
|
|
[NetworkCallable]
|
|
public void ChoiceCardInteract(int ChoiceNumber)
|
|
{
|
|
if (_SelectedChoice == ChoiceNumber)
|
|
{
|
|
RevealChoice();
|
|
return;
|
|
}
|
|
|
|
_SelectedChoice = ChoiceNumber;
|
|
|
|
VRCPlayerApi Player = Networking.GetOwner(_Podium.gameObject);
|
|
Debug.Assert(Player != null);
|
|
|
|
for (int i = 0; i < _ChoiceCards.Length; i++)
|
|
{
|
|
ChoiceCard Card = _ChoiceCards[i];
|
|
|
|
_PCCardAnimator.SetBool("Turn Forward", false);
|
|
Card.DisableInteractive = false;
|
|
|
|
if (Card.ChoiceNumber == _SelectedChoice)
|
|
{
|
|
if (!Player.IsUserInVR())
|
|
{
|
|
NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)Card, NetworkEventTarget.All, "SetToHeldPosition");
|
|
Card.DisableInteractive = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Card.ResetPosition();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void RevealChoice()
|
|
{
|
|
VRCPlayerApi Player = Networking.GetOwner(_Podium.gameObject);
|
|
if (Player != null && !Player.IsUserInVR())
|
|
{
|
|
for (int i = 0; i < _ChoiceCards.Length; i++)
|
|
{
|
|
ChoiceCard Card = _ChoiceCards[i];
|
|
|
|
if (Card.ChoiceNumber == _SelectedChoice)
|
|
{
|
|
VRCPickup Pickup = Card.GetComponent<VRCPickup>();
|
|
if (Pickup != null)
|
|
{
|
|
Pickup.Drop();
|
|
}
|
|
NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)Card, NetworkEventTarget.All, "SetToHeldPosition");
|
|
_PCCardAnimator.SetBool("Turn Forward", true);
|
|
Card.DisableInteractive = true;
|
|
}
|
|
else
|
|
{
|
|
Card.ResetPosition();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public int GetSelectedChoice()
|
|
{
|
|
return _SelectedChoice;
|
|
}
|
|
|
|
|
|
public void SetChoices(string[] Choices, int[] Indices)
|
|
{
|
|
for (int i = 0; i < _ChoiceCards.Length && i < _ChoiceCardText.Length; i++)
|
|
{
|
|
_ChoiceCards[Indices[i]].ChoiceNumber = (i + 1);
|
|
_ChoiceCardText[Indices[i]].text = Choices[i];
|
|
}
|
|
}
|
|
|
|
[NetworkCallable]
|
|
public void MakeChoiceTextVisible()
|
|
{
|
|
for (int i = 0; i < _ChoiceCards.Length && i < _ChoiceCardText.Length; i++)
|
|
{
|
|
_ChoiceCardText[i].gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void LockInChoice()
|
|
{
|
|
for (int i = 0; i < _ChoiceCards.Length; i++)
|
|
{
|
|
ChoiceCard Card = _ChoiceCards[i];
|
|
if (Card.ChoiceNumber == _SelectedChoice) { Card.DisableInteractive = false; continue; }
|
|
Card.DisableInteractive = true;
|
|
VRCPickup Pickup = Card.GetComponent<VRCPickup>();
|
|
if (Pickup != null) { Pickup.pickupable = false; }
|
|
}
|
|
}
|
|
|
|
public void ResetCards()
|
|
{
|
|
_SelectedChoice = -1;
|
|
|
|
VRCPlayerApi Player = Networking.GetOwner(_Podium.gameObject);
|
|
Debug.Assert(Player != null);
|
|
|
|
bool IsInVR = Player.IsUserInVR();
|
|
|
|
for (int i = 0; i < _ChoiceCards.Length; i++)
|
|
{
|
|
ChoiceCard Card = _ChoiceCards[i];
|
|
|
|
Card.ResetPosition();
|
|
_ChoiceCardText[i].text = "";
|
|
_ChoiceCardText[i].gameObject.SetActive(false);
|
|
|
|
Card.DisableInteractive = IsInVR;
|
|
|
|
VRCPickup Pickup = Card.GetComponent<VRCPickup>();
|
|
if (Pickup != null)
|
|
{
|
|
Pickup.pickupable = IsInVR;
|
|
}
|
|
}
|
|
|
|
_PCCardAnimator.SetBool("Turn Forward", false);
|
|
}
|
|
}
|