using MMMaellon.LightSync; using UdonSharp; using UnityEngine; 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 LightSync _ObjectSync; [UdonSynced] private bool _Active = false; [UdonSynced] private bool _CallHasBeenPlayed = false; private bool _Active_Cached = false; void Start() { _ObjectSync = GetComponent(); } public override void OnDeserialization(DeserializationResult Result) { _Activate_Synced(); base.OnDeserialization(Result); } public override void OnPickup() { if (Networking.LocalPlayer != _GameManager.GetHostOwner()) { Networking.SetOwner(Networking.LocalPlayer, gameObject); } base.OnPickup(); } public override void OnPickupUseDown() { if (Networking.LocalPlayer == _GameManager.GetHostOwner()) { PlayJailCall(); } base.OnPickupUseDown(); } public override void OnOwnershipTransferred(VRCPlayerApi Player) { _GameManager.SendCustomNetworkEvent(NetworkEventTarget.Owner, "FollowPlayerHoldingPhone", Player.displayName); PlayJailCall(); base.OnOwnershipTransferred(Player); } public void Initialise() { Activate(false); _CallHasBeenPlayed = false; RequestSerialization(); } public void Activate(bool Active) { _Active = Active; _Activate_Synced(); _ObjectSync.pickup.pickupable = _Active; RequestSerialization(); } private void _Activate_Synced() { if (_Active != _Active_Cached) { if (_Active) { _GameManager.PhoneRing(); } else { transform.localPosition = Vector3.zero; transform.localRotation = Quaternion.identity; } } _Active_Cached = _Active; } private void PlayJailCall() { if (_Active && !_CallHasBeenPlayed) { SendCustomEventDelayedSeconds(nameof(PlayJailCall_Delayed), 0.75f); _CallHasBeenPlayed = true; RequestSerialization(); } } public void PlayJailCall_Delayed() { _GameManager.SendCustomNetworkEvent(NetworkEventTarget.Owner, "PlayJailCall"); } }