SixdofTest.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Nxr.Internal;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. namespace NXR.Samples
  7. {
  8. public class SixdofTest : MonoBehaviour
  9. {
  10. public TextMesh PositionText;
  11. public TextMesh RotationText;
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15. NxrViewer.serviceReadyUpdatedDelegate += OnServiceReady;
  16. }
  17. void OnServiceReady(SERVICE_TYPE serviceType, bool isConnectedSucc)
  18. {
  19. Debug.Log("OnServiceReady---------------------" + serviceType + "," + isConnectedSucc);
  20. if (serviceType == SERVICE_TYPE.SIX_DOF)
  21. {
  22. bool support6DOF = NxrViewer.Instance.GetNibiruService().IsSupport6DOF();
  23. Debug.Log("Six Dof Support Status : " + (support6DOF ? 1 : 0));
  24. }
  25. }
  26. // Update is called once per frame
  27. void Update()
  28. {
  29. NxrHead head = NxrViewer.Instance.GetHead();
  30. if (head != null)
  31. {
  32. PositionText.text = "Pos:" + Math.Round(head.transform.position.x, 2) + "," +
  33. Math.Round(head.transform.position.y, 2) + "," +
  34. Math.Round(head.transform.position.z, 2);
  35. RotationText.text = "Rot:" + Math.Round(head.transform.eulerAngles.x, 2) + "," +
  36. Math.Round(head.transform.eulerAngles.y, 2) + "," +
  37. Math.Round(head.transform.eulerAngles.z, 2);
  38. }
  39. }
  40. void OnDestroy()
  41. {
  42. NxrViewer.serviceReadyUpdatedDelegate -= OnServiceReady;
  43. }
  44. }
  45. }