HeadTrackingScene.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using Rokid.UXR.Module;
  4. using Rokid.UXR.Utility;
  5. using Rokid.UXR.Native;
  6. namespace Rokid.UXR.Demo
  7. {
  8. public class HeadTrackingScene : AutoInjectBehaviour
  9. {
  10. [Autowrited]
  11. private Text infoTxt;
  12. [Autowrited]
  13. private Text engineTxt;
  14. [Autowrited]
  15. private Button zeroDofButton;
  16. [Autowrited]
  17. private Button threeDofButton;
  18. [Autowrited]
  19. private Button sixDofButton;
  20. private RKCameraRig cameraRig;
  21. public Camera mainCamera;
  22. void Start()
  23. {
  24. // Configures the app to not shut down the screen
  25. Screen.sleepTimeout = SleepTimeout.NeverSleep;
  26. NativeInterface.NativeAPI.Recenter(); // reset glass 3dof
  27. RKVirtualController.Instance.Change(ControllerType.NORMAL);
  28. if (mainCamera == null)
  29. {
  30. mainCamera = MainCameraCache.mainCamera;
  31. }
  32. cameraRig = mainCamera.GetComponent<RKCameraRig>();
  33. zeroDofButton.onClick.AddListener(() =>
  34. {
  35. cameraRig.headTrackingType = RKCameraRig.HeadTrackingType.None;
  36. });
  37. threeDofButton.onClick.AddListener(() =>
  38. {
  39. cameraRig.headTrackingType = RKCameraRig.HeadTrackingType.RotationOnly;
  40. });
  41. sixDofButton.onClick.AddListener(() =>
  42. {
  43. cameraRig.headTrackingType = RKCameraRig.HeadTrackingType.RotationAndPosition;
  44. });
  45. }
  46. private void Update()
  47. {
  48. if (RKNativeInput.Instance.GetKeyDown(RKKeyEvent.KEY_RESET) || Input.GetKeyDown(KeyCode.JoystickButton0)) //长按虚拟面板 HOME键事件
  49. {
  50. RKLog.Info("UXR-UNITY::KEY_RESET");
  51. NativeInterface.NativeAPI.Recenter();
  52. }
  53. infoTxt.text = string.Format("Position:{0}\r\nEuler:{1}\r\nRotation:{2}", mainCamera.transform.position.ToString("f3"), mainCamera.transform.rotation.eulerAngles.ToString(), mainCamera.transform.rotation.ToString("f3"));
  54. engineTxt.text = $"DebugInfo:{NativeInterface.NativeAPI.GetHeadTrackingStatus()},{NativeInterface.NativeAPI.GetDebugInfo()}";
  55. }
  56. private void OnEnable()
  57. {
  58. RKLog.Info("-UXR- HeadTrackingScene OnEnable");
  59. }
  60. private void OnBecameVisible()
  61. {
  62. RKLog.Info("-UXR- HeadTrackingScene OnBecameVisible ");
  63. }
  64. private void OnDisable()
  65. {
  66. RKLog.Info("-UXR- HeadTrackingScene OnDisable ");
  67. }
  68. }
  69. }