FolloHand.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using NRKernal;
  5. using UnityEngine;
  6. public class FolloHand : MonoBehaviour
  7. {
  8. public GameObject righthand;
  9. private void Start()
  10. {
  11. NRInput.Hands.OnHandStatesUpdated += OnHandStatesUpdated;
  12. }
  13. private void OnHandStatesUpdated()
  14. {
  15. var handState = NRInput.Hands.GetHandState(HandEnum.RightHand);
  16. if (handState != null && handState.isTracked)
  17. {
  18. foreach (var jointID in handState.jointsPoseDict.Keys)
  19. {
  20. if(jointID==HandJointID.Palm)
  21. {
  22. if(righthand==null)
  23. righthand = CreateJointObj(jointID);
  24. righthand.transform.position = handState.jointsPoseDict[jointID].position;
  25. righthand.transform.eulerAngles =new Vector3( handState.jointsPoseDict[jointID].rotation.eulerAngles.z+180, handState.jointsPoseDict[jointID].rotation.eulerAngles.y-100, handState.jointsPoseDict[jointID].rotation.eulerAngles.x);
  26. }
  27. }
  28. }
  29. else
  30. {
  31. }
  32. }
  33. private GameObject CreateJointObj(HandJointID handJointID)
  34. {
  35. return new GameObject();
  36. }
  37. // Update is called once per frame
  38. void Update()
  39. {
  40. if(righthand!=null)
  41. {
  42. this.transform.localPosition = OpenXRCamera.Instance.head.InverseTransformPoint(righthand.transform.position);
  43. this.transform.localEulerAngles = righthand.transform.eulerAngles-new Vector3(0,OpenXRCamera.Instance.head.eulerAngles.y,0);
  44. }
  45. }
  46. }