72 lines
1.8 KiB
C#
72 lines
1.8 KiB
C#
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using VRC.SDKBase;
|
|
|
|
|
|
[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
|
|
public class ViewTabletSpawner : UdonSharpBehaviour
|
|
{
|
|
[SerializeField] private Transform _ViewTabletHeadRoot;
|
|
[SerializeField] private Transform _ViewTabletHeadOffset;
|
|
[SerializeField] private Transform _ViewTablet;
|
|
|
|
private bool _FollowPlayerHead = false;
|
|
|
|
|
|
void Update()
|
|
{
|
|
VRCPlayerApi LocalPlayer = Networking.LocalPlayer;
|
|
|
|
if (_FollowPlayerHead)
|
|
{
|
|
_ViewTabletHeadRoot.position = LocalPlayer.GetBonePosition(HumanBodyBones.Head);
|
|
_ViewTabletHeadRoot.rotation = LocalPlayer.GetBoneRotation(HumanBodyBones.Head);
|
|
}
|
|
else
|
|
{
|
|
_ViewTabletHeadRoot.localPosition = Vector3.zero;
|
|
_ViewTabletHeadRoot.localRotation = Quaternion.identity;
|
|
}
|
|
}
|
|
|
|
//public override void OnPlayerRespawn(VRCPlayerApi Player)
|
|
//{
|
|
// if (Player.isLocal)
|
|
// {
|
|
// Vector3 HeadRotation = Networking.LocalPlayer.GetBoneRotation(HumanBodyBones.Head).eulerAngles;
|
|
// HeadRotation.x = HeadRotation.z = 0.0f;
|
|
// float DeltaY = HeadRotation.y - _PreviousHeadYRotation;
|
|
// HeadRotation.y = _ViewTabletHeadRoot.eulerAngles.y + DeltaY;
|
|
// _ViewTabletHeadRoot.rotation = Quaternion.Euler(HeadRotation);
|
|
// }
|
|
|
|
// base.OnPlayerRespawn(Player);
|
|
//}
|
|
|
|
|
|
public void SpawnAtLocalPlayerHead()
|
|
{
|
|
_ResetTabletPosition();
|
|
|
|
Vector3 HeadRotation = Networking.LocalPlayer.GetBoneRotation(HumanBodyBones.Head).eulerAngles;
|
|
HeadRotation.x = HeadRotation.z = 0.0f;
|
|
_ViewTabletHeadRoot.rotation = Quaternion.Euler(HeadRotation);
|
|
|
|
_FollowPlayerHead = true;
|
|
}
|
|
|
|
public void Despawn()
|
|
{
|
|
_ResetTabletPosition();
|
|
_FollowPlayerHead = false;
|
|
}
|
|
|
|
|
|
private void _ResetTabletPosition()
|
|
{
|
|
_ViewTablet.localPosition = Vector3.zero;
|
|
_ViewTablet.localRotation = Quaternion.identity;
|
|
}
|
|
}
|