API_Module_InputSystem.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using System;
  2. using UnityEngine;
  3. using SC.XR.Unity.Module_InputSystem;
  4. [Obsolete("Please Use API_GSXR_Module_InputSystem")]
  5. public class API_Module_InputSystem
  6. {
  7. ///API-No.50
  8. /// <summary>
  9. /// 获取Module_InputSystem的单例
  10. /// </summary>
  11. /// <returns></returns>
  12. public static Module_InputSystem GetInstance() {
  13. return Module_InputSystem.instance;
  14. }
  15. ///API-No.51
  16. /// <summary>
  17. /// Module_InputSystem是否初始化完成
  18. /// </summary>
  19. /// <returns>true 表示初始化完成,反之</returns>
  20. public static bool IsISInitialized() {
  21. if(Module_InputSystem.instance) {
  22. return Module_InputSystem.instance.initialize;
  23. }
  24. return false;
  25. }
  26. ///API-No.52
  27. /// <summary>
  28. /// 设置Module_InputSystem初始化完成时的回调
  29. /// </summary>
  30. /// <param name="action">委托的方法</param>
  31. public static void AddInitializedCallBack(Action action) {
  32. Module_InputSystem.instance.initializeCallBack += action;
  33. }
  34. ///API-No.53
  35. public static void RemoveInitializedCallBack(Action action) {
  36. Module_InputSystem.instance.initializeCallBack -= action;
  37. }
  38. ///API-No.54
  39. /// <summary>
  40. /// 使能某个输入设备,支持的输入设备见InputDeviceType
  41. /// </summary>
  42. /// <param name="inputDevice">输入设备</param>
  43. public static void EnableInputDevice(InputDeviceType inputDevice) {
  44. if(Module_InputSystem.instance) {
  45. Module_InputSystem.instance.SetActiveInputDevice(inputDevice,true);
  46. }
  47. }
  48. ///API-No.55
  49. /// <summary>
  50. /// 关闭某个输入设备,支持的输入设备见InputDeviceType
  51. /// </summary>
  52. /// <param name="inputDevice">输入设备</param>
  53. public static void DisableInputDevice(InputDeviceType inputDevice) {
  54. if(Module_InputSystem.instance) {
  55. Module_InputSystem.instance.SetActiveInputDevice(inputDevice,false);
  56. }
  57. }
  58. ///API-No.56
  59. ///监听某个按键事件方式1
  60. ///usingusing SC.XR.Unity.Module_InputSystem; 然后继承PointerHandlers类并重写需要的方法
  61. ///支持的事件有:
  62. ///OnPointerExit, OnPointerEnter, OnPointerDown,OnPointerClick,OnPointerUp, OnDrag
  63. ///API-No.57
  64. ///监听某个按键事件方式2
  65. ///using SC.XR.Unity.Module_InputSystem; 然后继承PointerDelegate类然后重写对应的事件
  66. ///支持的事件有:
  67. ///KeyUpDelegateUnRegister KeyUpDelegateRegister KeyLongDelegateRegister
  68. ///KeyLongDelegateUnRegister KeyDownDelegateUnRegister KeyDownDelegateRegister
  69. ///API-No.58
  70. /// <summary>
  71. /// 输入设备检测的目标,优先级为Head/BTRight/BTLeft/GTRight/GTLeft/GGTRight/GGLeft
  72. /// </summary>
  73. public static GameObject Target {
  74. get {
  75. if(API_Module_InputSystem_Head.Head != null) {
  76. return API_Module_InputSystem_Head.HeadHitTarget;
  77. } else if(API_Module_InputSystem_BT3Dof.BTRight != null) {
  78. return API_Module_InputSystem_BT3Dof.BTHitTarget(API_Module_InputSystem_BT3Dof.BTType.Right);
  79. } else if(API_Module_InputSystem_BT3Dof.BTLeft != null) {
  80. return API_Module_InputSystem_BT3Dof.BTHitTarget(API_Module_InputSystem_BT3Dof.BTType.Left);
  81. }else if(API_Module_InputSystem_GGT26Dof.GGTRight != null) {
  82. return API_Module_InputSystem_GGT26Dof.GGTHitTarget(API_Module_InputSystem_GGT26Dof.GGestureType.Right);
  83. } else if(API_Module_InputSystem_GGT26Dof.GGTLeft != null) {
  84. return API_Module_InputSystem_GGT26Dof.GGTHitTarget(API_Module_InputSystem_GGT26Dof.GGestureType.Left);
  85. }
  86. return null;
  87. }
  88. }
  89. ///API-No.59
  90. /// <summary>
  91. /// 输入设备的发射射线起点,优先级为Head/BTRight/BTLeft/GTRight/GTLeft/GGTRight/GGLeft
  92. /// </summary>
  93. public static GameObject Gazer {
  94. get {
  95. if(API_Module_InputSystem_Head.Head != null) {
  96. return API_Module_InputSystem_Head.Head.detectorBase.pointerBase.gameObject;
  97. } else if(API_Module_InputSystem_BT3Dof.BTRight != null) {
  98. return API_Module_InputSystem_BT3Dof.BTRight.bT3DofDetector.pointerBase.gameObject;
  99. } else if(API_Module_InputSystem_BT3Dof.BTLeft != null) {
  100. return API_Module_InputSystem_BT3Dof.BTLeft.bT3DofDetector.pointerBase.gameObject;
  101. }else if(API_Module_InputSystem_GGT26Dof.GGTRight != null) {
  102. return API_Module_InputSystem_GGT26Dof.GGTRight.detectorBase.pointerBase.gameObject;
  103. } else if(API_Module_InputSystem_GGT26Dof.GGTLeft != null) {
  104. return API_Module_InputSystem_GGT26Dof.GGTLeft.detectorBase.pointerBase.gameObject;
  105. }
  106. return null;
  107. }
  108. }
  109. ///API-No.60
  110. /// <summary>
  111. /// 输入设备的发射射线方向,优先级为Head/BTRight/BTLeft/GTRight/GTLeft/GGTRight/GGLeft
  112. /// </summary>
  113. public static Vector3 Normal {
  114. get {
  115. if(Gazer!=null) {
  116. return Gazer.transform.forward;
  117. }
  118. return Vector3.zero;
  119. }
  120. }
  121. ///API-No.61
  122. /// <summary>
  123. /// 输入设备Cursor的位置,优先级为Head/BTRight/BTLeft/GTRight/GTLeft/GGTRight/GGLeft
  124. /// </summary>
  125. public static Vector3 Position {
  126. get {
  127. if(API_Module_InputSystem_Head.Head != null) {
  128. return API_Module_InputSystem_Head.GetHeadCursor.transform.position;
  129. } else if(API_Module_InputSystem_BT3Dof.BTRight != null) {
  130. return API_Module_InputSystem_BT3Dof.GetBTCursor(API_Module_InputSystem_BT3Dof.BTType.Right).transform.position;
  131. } else if(API_Module_InputSystem_BT3Dof.BTLeft != null) {
  132. return API_Module_InputSystem_BT3Dof.GetBTCursor(API_Module_InputSystem_BT3Dof.BTType.Left).transform.position;
  133. }else if(API_Module_InputSystem_GGT26Dof.GGTRight != null) {
  134. return API_Module_InputSystem_GGT26Dof.GetGGTCursor(API_Module_InputSystem_GGT26Dof.GGestureType.Right).transform.position;
  135. } else if(API_Module_InputSystem_GGT26Dof.GGTLeft != null) {
  136. return API_Module_InputSystem_GGT26Dof.GetGGTCursor(API_Module_InputSystem_GGT26Dof.GGestureType.Left).transform.position;
  137. }
  138. return Vector3.zero;
  139. }
  140. }
  141. ///API-No.62
  142. /// <summary>
  143. /// 获取当前的具体输入设备,优先级为Head/BTRight/BTLeft/GTRight/GTLeft/GGTRight/GGLeft
  144. /// </summary>
  145. public static InputDevicePartBase InputDeviceCurrent {
  146. get {
  147. if(API_Module_InputSystem_Head.Head != null) {
  148. return API_Module_InputSystem_Head.Head;
  149. } else if(API_Module_InputSystem_BT3Dof.BTRight != null) {
  150. return API_Module_InputSystem_BT3Dof.BTRight;
  151. } else if(API_Module_InputSystem_BT3Dof.BTLeft != null) {
  152. return API_Module_InputSystem_BT3Dof.BTLeft;
  153. }
  154. return null;
  155. }
  156. }
  157. public static bool InputDeviceStatus(InputDeviceType deviceType) {
  158. if (Module_InputSystem.instance) {
  159. return Module_InputSystem.instance.GetInputDeviceStatus(deviceType);
  160. }
  161. return false;
  162. }
  163. }