XRAPIPanel.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using NRKernal;
  2. using UnityEngine;
  3. #if USING_XR_SDK
  4. using UnityEngine.XR;
  5. using System.Collections.Generic;
  6. #endif
  7. public class XRAPIPanel : MonoBehaviour
  8. {
  9. public const string display_match = "NRSDK Display";
  10. public const string input_match = "NRSDK Head Tracking";
  11. #if USING_XR_SDK
  12. private XRDisplaySubsystem mNrealXRDisplaySubsystem;
  13. private XRInputSubsystem mNrealXRInputSubsystem;
  14. #endif
  15. // Start is called before the first frame update
  16. void Start()
  17. {
  18. #if USING_XR_SDK && !UNITY_EDITOR
  19. List<XRDisplaySubsystemDescriptor> displays = new List<XRDisplaySubsystemDescriptor>();
  20. List<XRInputSubsystemDescriptor> inputs = new List<XRInputSubsystemDescriptor>();
  21. SubsystemManager.GetSubsystemDescriptors(displays);
  22. Debug.Log("[XRAPIPanel] Number of display providers found: " + displays.Count);
  23. foreach (var d in displays)
  24. {
  25. Debug.Log("[XRAPIPanel] Scanning display id: " + d.id);
  26. if (d.id.Contains(display_match))
  27. {
  28. Debug.Log("[XRAPIPanel] Creating display " + d.id);
  29. mNrealXRDisplaySubsystem = d.Create();
  30. if (mNrealXRDisplaySubsystem != null)
  31. {
  32. Debug.Log("[XRAPIPanel] Starting display " + d.id);
  33. mNrealXRDisplaySubsystem.Start();
  34. }
  35. }
  36. }
  37. SubsystemManager.GetSubsystemDescriptors(inputs);
  38. Debug.Log("[XRAPIPanel] Number of input providers found: " + inputs.Count);
  39. foreach (var i in inputs)
  40. {
  41. Debug.Log("[XRAPIPanel] Scanning input id: " + i.id);
  42. if (i.id.Contains(input_match))
  43. {
  44. Debug.Log("[XRAPIPanel] Creating input " + i.id);
  45. mNrealXRInputSubsystem = i.Create();
  46. if (mNrealXRInputSubsystem != null)
  47. {
  48. Debug.Log("[XRAPIPanel] Starting input " + i.id);
  49. mNrealXRInputSubsystem.Start();
  50. }
  51. }
  52. else
  53. {
  54. Debug.Log("[XRAPIPanel] input id not match: " + i.id);
  55. }
  56. }
  57. #endif
  58. }
  59. // Update is called once per frame
  60. void Update()
  61. {
  62. if (NRInput.GetButtonDown(ControllerButton.TRIGGER))
  63. {
  64. PrintLog();
  65. }
  66. }
  67. private void PrintLog()
  68. {
  69. #if USING_XR_SDK && !UNITY_EDITOR
  70. var reprojectionMode = mNrealXRDisplaySubsystem.reprojectionMode;
  71. var contentProtectionEnabled = mNrealXRDisplaySubsystem.contentProtectionEnabled;
  72. var displayOpaque = mNrealXRDisplaySubsystem.displayOpaque;
  73. var singlePassRenderingDisabled = mNrealXRDisplaySubsystem.singlePassRenderingDisabled;
  74. var renderPassCount = mNrealXRDisplaySubsystem.GetRenderPassCount();
  75. float appGPUTimeLastFrame = 0f;
  76. mNrealXRDisplaySubsystem.TryGetAppGPUTimeLastFrame(out appGPUTimeLastFrame);
  77. float gpuTimeLastFrameCompositor = 0f;
  78. mNrealXRDisplaySubsystem.TryGetCompositorGPUTimeLastFrame(out gpuTimeLastFrameCompositor);
  79. float displayRefreshRate = 0f;
  80. mNrealXRDisplaySubsystem.TryGetDisplayRefreshRate(out displayRefreshRate);
  81. int droppedFrameCount;
  82. mNrealXRDisplaySubsystem.TryGetDroppedFrameCount(out droppedFrameCount);
  83. int framePresentCount;
  84. mNrealXRDisplaySubsystem.TryGetFramePresentCount(out framePresentCount);
  85. float motionToPhoton;
  86. mNrealXRDisplaySubsystem.TryGetMotionToPhoton(out motionToPhoton);
  87. Debug.LogFormat("[XRAPIPanel] PrintLog---- reprojectionMode:{0} contentProtectionEnabled:{1} displayOpaque:{2} singlePassRenderingDisabled:{3} " +
  88. "renderPassCount:{4} appGPUTimeLastFrame:{5} gpuTimeLastFrameCompositor:{6} displayRefreshRate:{7} " +
  89. "droppedFrameCount:{8} framePresentCount:{9} motionToPhoton:{10}",
  90. reprojectionMode,
  91. contentProtectionEnabled,
  92. displayOpaque,
  93. singlePassRenderingDisabled,
  94. renderPassCount,
  95. appGPUTimeLastFrame.ToString("F3"),
  96. gpuTimeLastFrameCompositor.ToString("F3"),
  97. displayRefreshRate,
  98. droppedFrameCount,
  99. framePresentCount,
  100. motionToPhoton);
  101. #endif
  102. }
  103. }