165 lines
3.6 KiB
C#
165 lines
3.6 KiB
C#
|
|
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
|
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;
|
|
|
|
Debug.LogError("[[DEBUG]] Choice number is " + ChoiceNumber + "; selected choice is now " + _SelectedChoice);
|
|
}
|
|
|
|
[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);
|
|
|
|
if (Card.ChoiceNumber == _SelectedChoice)
|
|
{
|
|
if (!Player.IsUserInVR())
|
|
{
|
|
NetworkCalling.SendCustomNetworkEvent((IUdonEventReceiver)Card, NetworkEventTarget.All, "SetToHeldPosition");
|
|
}
|
|
}
|
|
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);
|
|
}
|
|
else
|
|
{
|
|
Card.ResetPosition();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public int GetSelectedChoice()
|
|
{
|
|
return _SelectedChoice;
|
|
}
|
|
|
|
|
|
public void SetChoices(string[] Choices, int[] Indices)
|
|
{
|
|
_ChoiceCards[Indices[0]].ChoiceNumber = 1;
|
|
_ChoiceCardText[Indices[0]].text = Choices[0];
|
|
|
|
_ChoiceCards[Indices[1]].ChoiceNumber = 2;
|
|
_ChoiceCardText[Indices[1]].text = Choices[1];
|
|
|
|
_ChoiceCards[Indices[2]].ChoiceNumber = 3;
|
|
_ChoiceCardText[Indices[2]].text = Choices[2];
|
|
}
|
|
|
|
public void LockInChoice()
|
|
{
|
|
for (int i = 0; i < _ChoiceCards.Length; i++)
|
|
{
|
|
ChoiceCard Card = _ChoiceCards[i];
|
|
if (Card.ChoiceNumber == _SelectedChoice) { 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 = "";
|
|
|
|
Card.DisableInteractive = IsInVR;
|
|
|
|
VRCPickup Pickup = Card.GetComponent<VRCPickup>();
|
|
if (Pickup != null)
|
|
{
|
|
Pickup.pickupable = IsInVR;
|
|
}
|
|
}
|
|
|
|
_PCCardAnimator.SetBool("Turn Forward", false);
|
|
_PCCardAnimator.Update(1.0f);
|
|
}
|
|
}
|