API_Module_InputSystem.cs 6.9 KB

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