- Host card spawner now switches ownership on interact to prevent sync issues. - Host card spawner now has an inset square collider to get in the way less. - Adjusted collision box of location board to not block the host card spawner. - Phone box cover now closes automatically when round 2 ends.
126 lines
2.8 KiB
C#
126 lines
2.8 KiB
C#
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using VRC.SDK3.Components;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon.Common;
|
|
using VRC.Udon.Common.Interfaces;
|
|
|
|
|
|
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
|
|
public class JailPhone : UdonSharpBehaviour
|
|
{
|
|
[SerializeField] private GameManagerRound2 _GameManager;
|
|
[SerializeField] private PermissionsPanel _PermissionsPanel;
|
|
[Space]
|
|
[SerializeField] private VRCPickup _PhonePickup;
|
|
[SerializeField] private Animator _PhoneBoxCoverAnimator;
|
|
|
|
[UdonSynced] private bool _Active = false;
|
|
[UdonSynced] private string _CallRecipient = "";
|
|
[UdonSynced] private bool _CallHasBeenPlayed = false;
|
|
|
|
private bool _Active_Cached = false;
|
|
|
|
|
|
public override void OnDeserialization(DeserializationResult Result)
|
|
{
|
|
_Activate_Synced();
|
|
|
|
base.OnDeserialization(Result);
|
|
}
|
|
|
|
public override void OnOwnershipTransferred(VRCPlayerApi Player)
|
|
{
|
|
Networking.SetOwner(Player, _PhonePickup.gameObject);
|
|
|
|
base.OnOwnershipTransferred(Player);
|
|
}
|
|
|
|
public void HostEnabled()
|
|
{
|
|
_ResetPickupability();
|
|
}
|
|
public void HostDisabled()
|
|
{
|
|
_ResetPickupability();
|
|
}
|
|
|
|
public void JailPhonePickedUp()
|
|
{
|
|
VRCPlayerApi LocalPlayer = Networking.LocalPlayer;
|
|
if (LocalPlayer.displayName == _CallRecipient)
|
|
{
|
|
PlayJailCall();
|
|
}
|
|
|
|
base.OnPickup();
|
|
}
|
|
|
|
|
|
public void Initialise()
|
|
{
|
|
Activate(false);
|
|
_CallHasBeenPlayed = false;
|
|
|
|
RequestSerialization();
|
|
}
|
|
|
|
public void Activate(bool Active, string CallRecipient = "")
|
|
{
|
|
Networking.SetOwner(Networking.LocalPlayer, _PhonePickup.gameObject);
|
|
|
|
if (_GameManager.IsRoundInitialised())
|
|
{
|
|
_Active = Active;
|
|
_CallRecipient = CallRecipient;
|
|
_Activate_Synced();
|
|
|
|
RequestSerialization();
|
|
}
|
|
}
|
|
private void _Activate_Synced()
|
|
{
|
|
if (_Active != _Active_Cached)
|
|
{
|
|
if (_Active)
|
|
{
|
|
_GameManager.PhoneRing();
|
|
}
|
|
else
|
|
{
|
|
_PhonePickup.transform.localPosition = Vector3.zero;
|
|
_PhonePickup.transform.localRotation = Quaternion.identity;
|
|
|
|
_PhoneBoxCoverAnimator.SetBool("Open", false);
|
|
}
|
|
}
|
|
|
|
_ResetPickupability();
|
|
|
|
_Active_Cached = _Active;
|
|
}
|
|
private void _ResetPickupability()
|
|
{
|
|
_PhonePickup.AutoHold = Networking.LocalPlayer.IsUserInVR() ? VRC_Pickup.AutoHoldMode.No : VRC_Pickup.AutoHoldMode.Yes;
|
|
_PhonePickup.pickupable = _Active && (Networking.LocalPlayer.displayName == _CallRecipient || _PermissionsPanel.IsPlayerHost(Networking.LocalPlayer));
|
|
}
|
|
|
|
|
|
private void PlayJailCall()
|
|
{
|
|
if (_Active && !_CallHasBeenPlayed)
|
|
{
|
|
_GameManager.SendCustomNetworkEvent(NetworkEventTarget.Owner, "FollowPlayerHoldingPhone", _CallRecipient);
|
|
|
|
SendCustomEventDelayedSeconds(nameof(PlayJailCall_Delayed), 0.75f);
|
|
_CallHasBeenPlayed = true;
|
|
RequestSerialization();
|
|
}
|
|
}
|
|
public void PlayJailCall_Delayed()
|
|
{
|
|
_GameManager.SendCustomNetworkEvent(NetworkEventTarget.Owner, "PlayJailCall");
|
|
}
|
|
}
|