HostInfo.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using SC.XR.Unity;
  2. using System.Collections.Generic;
  3. using TMPro;
  4. using UnityEngine;
  5. using static API_GSXR_Slam;
  6. public class HostInfo : MonoBehaviour
  7. {
  8. #region CanvasText
  9. [SerializeField]
  10. private TextMeshProUGUI XRType;
  11. [SerializeField]
  12. private TextMeshProUGUI DeviceName;
  13. [SerializeField]
  14. private TextMeshProUGUI SN;
  15. [SerializeField]
  16. private TextMeshProUGUI Internal_VERSION;
  17. [SerializeField]
  18. private TextMeshProUGUI IsSupportController;
  19. [SerializeField]
  20. private TextMeshProUGUI IsSupportHandTracking;
  21. [SerializeField]
  22. private TextMeshProUGUI IsSupportMap;
  23. [SerializeField]
  24. private TextMeshProUGUI IsSupportPanel;
  25. [SerializeField]
  26. private TextMeshProUGUI BatteryLevel;
  27. [SerializeField]
  28. private TextMeshProUGUI accelerometer;
  29. [SerializeField]
  30. private TextMeshProUGUI gyro_gravity;
  31. [SerializeField]
  32. private TextMeshProUGUI head_Position;
  33. [SerializeField]
  34. private TextMeshProUGUI head_Rotation;
  35. [SerializeField]
  36. private TextMeshProUGUI L_renderer;
  37. [SerializeField]
  38. private TextMeshProUGUI R_renderer;
  39. [SerializeField]
  40. private TextMeshProUGUI Volume;
  41. [SerializeField]
  42. private TextMeshProUGUI WIFI;
  43. [SerializeField]
  44. private TextMeshProUGUI Back;
  45. [SerializeField]
  46. private TextMeshProUGUI Enter;
  47. [SerializeField]
  48. private GameObject Headsetbutton;
  49. #endregion
  50. public static string xrType;
  51. private Gyroscope gyro;
  52. List<RenderTexture> list = new List<RenderTexture>();
  53. private void Awake()
  54. {
  55. API_GSXR_Slam.GSXR_Add_InitializedCallBack(ShowDeviceInfo);
  56. }
  57. private void Start()
  58. {
  59. gyro = Input.gyro;
  60. gyro.enabled = true;
  61. }
  62. private void Update()
  63. {
  64. //if (API_GSXR_Slam.SlamManager == null && !API_GSXR_Slam.SlamManager.IsRunning)
  65. //{
  66. // return;
  67. //}
  68. ShowHeadSensor();
  69. ShowKeyState();
  70. }
  71. private void LateUpdate()
  72. {
  73. //if (API_GSXR_Slam.SlamManager == null && !API_GSXR_Slam.SlamManager.IsRunning)
  74. //{
  75. // return;
  76. //}
  77. ShowRenderer();
  78. ShowOtherInfo();
  79. }
  80. private void OnDestroy()
  81. {
  82. API_GSXR_Slam.GSXR_Remove_InitializedCallBack(ShowDeviceInfo);
  83. }
  84. private void ShowDeviceInfo()
  85. {
  86. if (GSXR_Is_SlamInitialized())
  87. {
  88. xrType = API_GSXR_Slam.plugin.GSXR_Get_XRType().ToString();
  89. XRType.text = "XRType:" + xrType;
  90. DeviceName.text = "DeviceName:" + API_GSXR_Slam.plugin.GSXR_Get_DeviceName();
  91. if (API_GSXR_Slam.plugin.GSXR_Get_DeviceName() != "Sonic")
  92. {
  93. Headsetbutton.gameObject.SetActive(false);
  94. }
  95. SN.text = "SN:" + API_GSXR_Slam.plugin.SN;
  96. Internal_VERSION.text = "Internal_VERSION:" + API_GSXR_Slam.plugin.GSXR_Get_InternalVersion();
  97. IsSupportController.text = "Controller:" + (API_GSXR_Slam.plugin.GSXR_Is_SupportController()==true? "Yes":"No");
  98. IsSupportHandTracking.text = "HandTracking:" + (API_GSXR_Slam.plugin.GSXR_Is_SupportHandTracking() == true ? "Yes" : "No");
  99. IsSupportMap.text = "SpatialAwareness:" + (API_GSXR_Slam.plugin.GSXR_Support_Map() == true ? "Yes" : "No");
  100. IsSupportPanel.text = "PlaneDetection:" + (API_GSXR_Slam.plugin.GSXR_Support_Panel() == true ? "Yes" : "No");
  101. }
  102. }
  103. private void ShowHeadSensor()
  104. {
  105. accelerometer.text = "Accelerometer:" + Input.acceleration;
  106. gyro_gravity.text = "Gyro.Gravity:" + gyro.gravity;
  107. head_Position.text = "Position:" + SlamManager.head.position.ToString("f3");
  108. head_Rotation.text = "Rotation:" + SlamManager.head.rotation.ToString("f3");
  109. }
  110. private void ShowOtherInfo()
  111. {
  112. if (GSXR_Is_SlamInitialized())
  113. {
  114. BatteryLevel.text = "BatteryLevel:" + API_Module_BatteryStatus.BatteryLevel;
  115. Volume.text = "Volume:"+ API_Module_DetectorSystem_Volume.GetVolume().ToString();
  116. WIFI.text = "WIFI:"+ (NetStatus.Instance.SCIsConnectWifi()? "Connected":"Disconnected");
  117. }
  118. }
  119. private void ShowRenderer()
  120. {
  121. if (GSXR_Is_SlamInitialized())
  122. {
  123. list = GSXR_Get_RenderTexure();
  124. if (list.Count > 0 && list[0] != null)
  125. {
  126. L_renderer.text = "Left eye render resolution:" + list[0].width + " * " + list[0].height;
  127. R_renderer.text = "Right eye render resolution:" + list[1].width + " * " + list[1].height;
  128. }
  129. }
  130. }
  131. private void ShowKeyState()
  132. {
  133. if (API_GSXR_Slam.plugin.GSXR_Get_DeviceName() == "Sonic")
  134. {
  135. if (Input.GetKeyDown(KeyCode.JoystickButton0))
  136. {
  137. Enter.text = "Enter: Down";
  138. }
  139. if (Input.GetKeyUp(KeyCode.JoystickButton0))
  140. {
  141. Enter.text = "Enter: Up";
  142. }
  143. if (Input.GetKeyDown(KeyCode.Escape))
  144. {
  145. Back.text = "Back: Down";
  146. }
  147. if (Input.GetKeyUp(KeyCode.Escape))
  148. {
  149. Back.text = "Back: Up";
  150. }
  151. }
  152. }
  153. }