161 lines
3.8 KiB
C#
161 lines
3.8 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()
|
|
{
|
|
VRCPlayerApi Player = Networking.GetOwner(_Podium.gameObject);
|
|
Debug.Assert(Player != null);
|
|
|
|
for (int i = 0; i < _ChoiceCards.Length; i++)
|
|
{
|
|
ChoiceCard Card = _ChoiceCards[i];
|
|
|
|
Card.SetCardGroup(this);
|
|
|
|
bool IsInVR = Player.IsUserInVR();
|
|
|
|
Card.DisableInteractive = IsInVR;
|
|
VRCPickup Pickup = Card.GetComponent<VRCPickup>();
|
|
if (Pickup != null)
|
|
{
|
|
Pickup.pickupable = IsInVR;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ChoiceCardPickedUp(int ChoiceNumber)
|
|
{
|
|
_SelectedChoice = ChoiceNumber;
|
|
}
|
|
|
|
[NetworkCallable]
|
|
public void ChoiceCardInteract(int ChoiceNumber)
|
|
{
|
|
if (_SelectedChoice == ChoiceNumber)
|
|
{
|
|
RevealChoice();
|
|
return;
|
|
}
|
|
|
|
_SelectedChoice = ChoiceNumber;
|
|
|
|
Debug.LogWarning("[[DEBUG]] Selected choice is " + _SelectedChoice);
|
|
|
|
VRCPlayerApi Player = Networking.GetOwner(_Podium.gameObject);
|
|
Debug.Assert(Player != null);
|
|
|
|
for (int i = 0; i < _ChoiceCards.Length; i++)
|
|
{
|
|
ChoiceCard Card = _ChoiceCards[i];
|
|
|
|
Debug.LogWarning("[[DEBUG]] Card choice for index " + i + " is " + Card.ChoiceNumber);
|
|
|
|
_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 Choice1, string Choice2, string Choice3)
|
|
{
|
|
VRCPlayerApi Player = Networking.GetOwner(_Podium.gameObject);
|
|
float RandomSeed = (Player.GetPosition().x * 100) + (Player.GetPosition().z * 1000);
|
|
Random.InitState((int)RandomSeed);
|
|
|
|
int[] ChoiceIndices = { 0, 1, 2 };
|
|
|
|
int Choice1Index = ChoiceIndices[Random.Range(0, 3)];
|
|
_ChoiceCards[Choice1Index].ChoiceNumber = 1;
|
|
_ChoiceCardText[Choice1Index].text = Choice1;
|
|
ChoiceIndices[Choice1Index] = -1;
|
|
|
|
int Choice2Index = -1;
|
|
while(Choice2Index == -1) { Choice2Index = ChoiceIndices[Random.Range(0, 3)]; }
|
|
_ChoiceCards[Choice2Index].ChoiceNumber = 2;
|
|
_ChoiceCardText[Choice2Index].text = Choice2;
|
|
ChoiceIndices[Choice2Index] = -1;
|
|
|
|
int Choice3Index = -1;
|
|
while (Choice3Index == -1) { Choice3Index = ChoiceIndices[Random.Range(0, 3)]; }
|
|
_ChoiceCards[Choice3Index].ChoiceNumber = 3;
|
|
_ChoiceCardText[Choice3Index].text = Choice3;
|
|
ChoiceIndices[Choice3Index] = -1;
|
|
}
|
|
|
|
public void ResetCards()
|
|
{
|
|
_SelectedChoice = -1;
|
|
|
|
for (int i = 0; i < _ChoiceCards.Length; i++)
|
|
{
|
|
_ChoiceCards[i].ResetPosition();
|
|
_ChoiceCardText[i].text = "";
|
|
}
|
|
}
|
|
}
|