- Secret Vulpine trigger is now network synced. - Horseshoe is now network synced. Continuous for now, manual sync is planned.
164 lines
3.6 KiB
C#
164 lines
3.6 KiB
C#
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using UnityEngine.Animations;
|
|
using VRC.SDK3.ClientSim;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon;
|
|
|
|
public class Horseshoe : UdonSharpBehaviour
|
|
{
|
|
public GameObject HomeLocation;
|
|
|
|
[UdonSynced, FieldChangeCallback(nameof(SetHeld))]
|
|
private bool _IsBeingHeld = false;
|
|
|
|
[UdonSynced, FieldChangeCallback(nameof(SetInHome))]
|
|
private bool _IsInHome = true;
|
|
|
|
[UdonSynced, FieldChangeCallback(nameof(SetHungOnHook))]
|
|
private bool _IsHungOnHook = true;
|
|
|
|
//[UdonSynced(UdonSyncMode.Linear), FieldChangeCallback(nameof(UpdateSyncedPosition))]
|
|
//private Vector3 _SyncedPosition;
|
|
//[UdonSynced(UdonSyncMode.Linear), FieldChangeCallback(nameof(UpdateSyncedRotation))]
|
|
//private Quaternion _SyncedRotation;
|
|
|
|
private Collider _HomeCollider;
|
|
|
|
private Rigidbody _HorseshoeRigidBody;
|
|
private ParentConstraint _HorseshoeConstraint;
|
|
|
|
|
|
public void Start()
|
|
{
|
|
_HomeCollider = HomeLocation.GetComponent<Collider>();
|
|
_HorseshoeRigidBody = GetComponent<Rigidbody>();
|
|
_HorseshoeConstraint = GetComponent<ParentConstraint>();
|
|
}
|
|
|
|
public override void OnPickup()
|
|
{
|
|
Networking.SetOwner(Networking.LocalPlayer, gameObject);
|
|
|
|
SetProgramVariable("_IsBeingHeld", true);
|
|
SetProgramVariable("_IsHungOnHook", false);
|
|
|
|
base.OnPickup();
|
|
}
|
|
|
|
public override void OnDrop()
|
|
{
|
|
SetProgramVariable("_IsBeingHeld", false);
|
|
|
|
if (_IsInHome)
|
|
{
|
|
SetProgramVariable("_IsHungOnHook", true);
|
|
}
|
|
|
|
base.OnDrop();
|
|
}
|
|
|
|
public void OnTriggerEnter(Collider OtherCollider)
|
|
{
|
|
if (CollidingObjectIsHome(OtherCollider))
|
|
{
|
|
SetProgramVariable("_IsInHome", true);
|
|
|
|
if (!_IsBeingHeld)
|
|
{
|
|
SetProgramVariable("_IsHungOnHook", true);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnTriggerExit(Collider OtherCollider)
|
|
{
|
|
if (CollidingObjectIsHome(OtherCollider))
|
|
{
|
|
SetProgramVariable("_IsInHome", false);
|
|
}
|
|
}
|
|
|
|
//public override void PostLateUpdate()
|
|
//{
|
|
// if (_IsBeingHeld)
|
|
// {
|
|
// SetProgramVariable("_SyncedPosition", gameObject.transform.position);
|
|
// SetProgramVariable("_SyncedRotation", gameObject.transform.rotation);
|
|
// }
|
|
|
|
// base.PostLateUpdate();
|
|
//}
|
|
|
|
|
|
private bool CollidingObjectIsHome(Collider OtherCollider)
|
|
{
|
|
if (OtherCollider.Equals(_HomeCollider))
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
public bool SetHeld
|
|
{
|
|
set
|
|
{
|
|
_IsBeingHeld = value;
|
|
_HorseshoeRigidBody.useGravity = (!_IsBeingHeld && !_IsHungOnHook);
|
|
}
|
|
|
|
get => _IsBeingHeld;
|
|
}
|
|
|
|
public bool SetInHome
|
|
{
|
|
set
|
|
{
|
|
_IsInHome = value;
|
|
}
|
|
|
|
get => _IsInHome;
|
|
}
|
|
|
|
public bool SetHungOnHook
|
|
{
|
|
set
|
|
{
|
|
_IsHungOnHook = value;
|
|
|
|
_HorseshoeConstraint.enabled = _IsHungOnHook;
|
|
if (_IsHungOnHook)
|
|
{
|
|
_HorseshoeRigidBody.useGravity = false;
|
|
}
|
|
}
|
|
|
|
get => _IsHungOnHook;
|
|
}
|
|
|
|
//public Vector3 UpdateSyncedPosition
|
|
//{
|
|
// set
|
|
// {
|
|
// _SyncedPosition = value;
|
|
// gameObject.transform.position = _SyncedPosition;
|
|
// }
|
|
|
|
// get => _SyncedPosition;
|
|
//}
|
|
|
|
//public Quaternion UpdateSyncedRotation
|
|
//{
|
|
// set
|
|
// {
|
|
// _SyncedRotation = value;
|
|
// gameObject.transform.rotation = _SyncedRotation;
|
|
// }
|
|
|
|
// get => _SyncedRotation;
|
|
//}
|
|
}
|