XRMan.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using EZXR.Glass.Inputs;
  2. using EZXR.Glass.SixDof;
  3. #if SpatialComputing
  4. using EZXR.Glass.SpatialComputing;
  5. #endif
  6. using UnityEngine;
  7. namespace EZXR.Glass.Core
  8. {
  9. [ScriptExecutionOrder(-58)]
  10. public class XRMan : MonoBehaviour
  11. {
  12. #region 单例
  13. private static XRMan instance;
  14. public static XRMan Instance
  15. {
  16. get
  17. {
  18. return instance;
  19. }
  20. }
  21. #endregion
  22. #region Encapsulation
  23. //SixDof
  24. public HMDPoseTracker.DegreeOfFreedom m_dof = HMDPoseTracker.DegreeOfFreedom.SixDof;
  25. public class TwoEyes
  26. {
  27. public Camera left
  28. {
  29. get
  30. {
  31. return HMDPoseTracker.Instance.leftCamera;
  32. }
  33. }
  34. public Camera right
  35. {
  36. get
  37. {
  38. return HMDPoseTracker.Instance.rightCamera;
  39. }
  40. }
  41. }
  42. public TwoEyes Eyes;
  43. //Hand
  44. public class TwoHands
  45. {
  46. /// <summary>
  47. /// 记录了左手柄的所有信息
  48. /// </summary>
  49. public InputInfoBase left
  50. {
  51. get
  52. {
  53. return InputSystem.leftHand;
  54. }
  55. }
  56. /// <summary>
  57. /// 记录了右手柄的所有信息
  58. /// </summary>
  59. public InputInfoBase right
  60. {
  61. get
  62. {
  63. return InputSystem.rightHand;
  64. }
  65. }
  66. }
  67. public TwoHands Hands;
  68. #endregion
  69. /// <summary>
  70. /// 专门用于放置各种附加组件
  71. /// </summary>
  72. public Transform attachments;
  73. [HideInInspector]
  74. public Vector3 position_SpatialTracking;
  75. [HideInInspector]
  76. public Quaternion rotation_SpatialTracking;
  77. [HideInInspector]
  78. public Vector3 position_SpatialComputing;
  79. [HideInInspector]
  80. public Quaternion rotation_SpatialComputing;
  81. [HideInInspector]
  82. public Matrix4x4 offset_SpatialComputing = Matrix4x4.identity;
  83. Vector3 tempPosition;
  84. Quaternion tempRotation;
  85. Matrix4x4 tempMatrix;
  86. private void Awake()
  87. {
  88. instance = this;
  89. if (attachments == null)
  90. {
  91. attachments = transform.Find("Attachments");
  92. }
  93. }
  94. // Start is called before the first frame update
  95. void Start()
  96. {
  97. InvokeRepeating("DoFramerate", 0, 1);
  98. }
  99. void DoFramerate()
  100. {
  101. Utilities.Android.SendIntent("ToSystem", "com.ezxr.glass.systemui", "DebugInfo", (1 / Time.smoothDeltaTime).ToString("##.#"));
  102. }
  103. // Update is called once per frame
  104. void Update()
  105. {
  106. if (HMDPoseTracker.Instance != null)
  107. {
  108. tempPosition = position_SpatialTracking;
  109. tempRotation = rotation_SpatialTracking;
  110. }
  111. #if SpatialComputing
  112. if (EZXRSpatialComputingManager.Instance != null)
  113. {
  114. tempMatrix = offset_SpatialComputing * Matrix4x4.TRS(tempPosition, tempRotation, Vector3.one);
  115. tempPosition = tempMatrix.GetColumn(3);
  116. tempRotation = tempMatrix.rotation;
  117. }
  118. #endif
  119. transform.position = tempPosition;
  120. transform.rotation = tempRotation;
  121. }
  122. }
  123. }