using MMMaellon.LightSync; 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 VRCPickup _PhonePickup; [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 void JailPhonePickedUp() { VRCPlayerApi LocalPlayer = Networking.LocalPlayer; Networking.SetOwner(LocalPlayer, gameObject); if (LocalPlayer.displayName == _CallRecipient) { PlayJailCall(); } base.OnPickup(); } public void Initialise() { Activate(false); _CallHasBeenPlayed = false; RequestSerialization(); } public void Activate(bool Active, string CallRecipient = "") { if (_GameManager.IsRoundInitialised()) { _Active = Active; _CallRecipient = CallRecipient; _Activate_Synced(); RequestSerialization(); } } private void _Activate_Synced() { if (_Active != _Active_Cached) { if (_Active) { _GameManager.PhoneRing(); } else { transform.localPosition = Vector3.zero; transform.localRotation = Quaternion.identity; } } _PhonePickup.pickupable = _Active && (Networking.LocalPlayer == _GameManager.GetHostOwner() || Networking.LocalPlayer.displayName == _CallRecipient); _Active_Cached = _Active; } 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"); } }