using UnityEngine;
using Photon.Pun;
public class NetworkPlayer : MonoBehaviour
{
public Transform head;
public Transform leftHand;
public Transform rightHand;
private PhotonView photonView;
public Animator leftHandAnimator;
public Animator rightHandAnimator;
private Transform headRig;
private Transform leftHandRig;
private Transform rightHandRig;
void Start()
{
photonView = GetComponent<PhotonView>();
OVRCameraRig rig = FindObjectOfType<OVRCameraRig>();
headRig = rig.centerEyeAnchor;
leftHandRig = rig.leftHandAnchor;
rightHandRig = rig.rightHandAnchor;
if (photonView.IsMine)
{
foreach (var item in GetComponentsInChildren<Renderer>())
{
item.enabled = false;
}
}
}
void Update()
{
if (photonView.IsMine)
{
MapPosition(head, headRig);
MapPosition(leftHand, leftHandRig);
MapPosition(rightHand, rightHandRig);
UpdateHandAnimation(OVRInput.Controller.LTouch, leftHandAnimator);
UpdateHandAnimation(OVRInput.Controller.RTouch, rightHandAnimator);
}
}
void UpdateHandAnimation(OVRInput.Controller controller, Animator handAnimator)
{
float triggerValue = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, controller);
handAnimator.SetFloat("Trigger", triggerValue);
float gripValue = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, controller);
handAnimator.SetFloat("Grip", gripValue);
}
void MapPosition(Transform target, Transform rigTransform)
{
target.position = rigTransform.position;
target.rotation = rigTransform.rotation;
}
}