Jamie Greunbaum 2281fae54e - Location board syncs much more reliably, and with less NetworkCallables.
- Jail chain syncs properly and disables itself, regardless of ownership.
- Also did some work with the cameras in round 2.
2025-12-22 03:38:38 -05:00

99 lines
2.1 KiB
C#

using UdonSharp;
using UnityEngine;
using VRC.SDK3.Components;
using VRC.Udon.Common.Interfaces;
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
public class JailChain : UdonSharpBehaviour
{
[SerializeField] private GameManagerRound2 _GameManager;
[Space]
[SerializeField] private VRCPickup _Pickup;
[SerializeField] private Transform _ChainPivot;
[SerializeField] private Transform _ChainHome;
[SerializeField] private Transform _PullTarget;
[Space]
[SerializeField] private Animator _JailChainAnimator;
[Space]
[Tooltip("Speed at which the chain returns to its neutral pose.")]
[SerializeField] private float _ReturnSpeedMultiplier = 5.0f;
[UdonSynced, FieldChangeCallback(nameof(Show))] private bool _Show = false;
[UdonSynced] private bool _PullChain = false;
[UdonSynced] private bool _HasBeenActivated = false;
public override void PostLateUpdate()
{
if (_PullChain)
{
if (!_HasBeenActivated && transform.localPosition.z < _PullTarget.transform.localPosition.z)
{
_HasBeenActivated = true;
RequestSerialization();
_GameManager.SendCustomNetworkEvent(NetworkEventTarget.Owner, "PlayInJailAnimation");
}
}
else
{
transform.localPosition = Vector3.Lerp(transform.localPosition, Vector3.zero, Time.deltaTime * _ReturnSpeedMultiplier);
}
_ChainPivot.LookAt(_ChainHome.transform);
base.PostLateUpdate();
}
public override void OnPickup()
{
_PullChain = true;
RequestSerialization();
base.OnPickup();
}
public override void OnDrop()
{
_PullChain = false;
if (_HasBeenActivated)
{
_Pickup.pickupable = false;
SendCustomEventDelayedSeconds(nameof(HideJailChain), 3.0f);
}
RequestSerialization();
base.OnDrop();
}
public void HideJailChain()
{
Show = false;
}
public void Initialise()
{
_PullChain = false;
_HasBeenActivated = false;
transform.localPosition = Vector3.zero;
_ChainPivot.localRotation = Quaternion.identity;
Show = false;
RequestSerialization();
}
public bool Show
{
set
{
_Show = value;
if (_Show) _Pickup.pickupable = true;
_JailChainAnimator.SetBool("Show", _Show);
RequestSerialization();
}
get => _Show;
}
}