API_InputSystem.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using System;
  2. using UnityEngine;
  3. using SC.InputSystem;
  4. using SC.InputSystem.InputDeviceHead;
  5. using SC.InputSystem.InputDeviceHandShank;
  6. using SC.InputSystem.InputDevice26DofGesture;
  7. public class API_InputSystem {
  8. ///API-No.50
  9. /// <summary>
  10. /// 获取InputSystem的单例
  11. /// </summary>
  12. /// <returns></returns>
  13. public static InputSystem GetInstant() {
  14. return InputSystem.Instant;
  15. }
  16. ///API-No.51
  17. /// <summary>
  18. /// Inputsystem是否初始化完成
  19. /// </summary>
  20. /// <returns>true 表示初始化完成,反之</returns>
  21. public static bool IsISInitialized() {
  22. if(InputSystem.Instant) {
  23. return InputSystem.Instant.Initialize;
  24. }
  25. return false;
  26. }
  27. ///API-No.52
  28. /// <summary>
  29. /// 设置InputSystem初始化完成时的回调
  30. /// </summary>
  31. /// <param name="action">委托的方法</param>
  32. public static void AddInitializedCallBack(Action action) {
  33. InputSystem.ISInitializeCallBack += action;
  34. }
  35. ///API-No.53
  36. public static void RemoveInitializedCallBack(Action action) {
  37. InputSystem.ISInitializeCallBack -= action;
  38. }
  39. ///API-No.54
  40. /// <summary>
  41. /// 使能某个输入设备,支持的输入设备见InputDeviceType
  42. /// </summary>
  43. /// <param name="inputDevice">输入设备</param>
  44. public static void EnableInputDeivce(InputDeviceType inputDevice) {
  45. if(InputSystem.Instant) {
  46. InputSystem.Instant.RegisterInputDevice(inputDevice);
  47. }
  48. }
  49. ///API-No.55
  50. /// <summary>
  51. /// 关闭某个输入设备,支持的输入设备见InputDeviceType
  52. /// </summary>
  53. /// <param name="inputDevice">输入设备</param>
  54. public static void DisableInputDeivce(InputDeviceType inputDevice) {
  55. if(InputSystem.Instant) {
  56. InputSystem.Instant.UnRegisterInputDevice(inputDevice);
  57. }
  58. }
  59. ///API-No.56
  60. ///监听某个按键事件方式1
  61. ///using SC.InputSystem ; 然后继承PointerHandlers类并重写需要的方法
  62. ///支持的事件有:
  63. ///OnSCPointerDown OnSCPointerEnter OnSCPointerExit OnSCPointerDrag OnSCPointerUp
  64. ///OnSCBothHandPointerDown OnSCBothHandPointerDrag OnSCBothHandPointerUp
  65. ///API-No.57
  66. ///监听某个按键事件方式2
  67. ///using SC.InputSystem ; 然后继承PointerDelegate类然后重写对应的事件
  68. ///支持的事件有:
  69. ///partAnyKeyDownDelegate partAnyKeyLongDelegate partAnyKeyUpDelegate partEnterKeyDownDelegate partEnterKeyDragDelegate partEnterKeyUpDelegate
  70. ///API-No.58
  71. /// <summary>
  72. /// 输入设备检测的目标,优先级为Head/BTRight/BTLeft/GTRight/GTLeft
  73. /// </summary>
  74. public static GameObject Target {
  75. get {
  76. if(API_InputSystem_Head.Head != null) {
  77. return API_InputSystem_Head.HeadHitTarget;
  78. } else if(API_InputSystem_Bluetooth.BTRight != null) {
  79. return API_InputSystem_Bluetooth.BTHitTarget(API_InputSystem_Bluetooth.BTType.Right);
  80. } else if(API_InputSystem_Bluetooth.BTLeft != null) {
  81. return API_InputSystem_Bluetooth.BTHitTarget(API_InputSystem_Bluetooth.BTType.Left);
  82. } else if(API_InputSystem_Gesture26Dof.GTRight != null) {
  83. return API_InputSystem_Gesture26Dof.GTHitTarget(API_InputSystem_Gesture26Dof.GestureType.Right);
  84. } else if(API_InputSystem_Gesture26Dof.GTLeft != null) {
  85. return API_InputSystem_Gesture26Dof.GTHitTarget(API_InputSystem_Gesture26Dof.GestureType.Left);
  86. }
  87. return null;
  88. }
  89. }
  90. ///API-No.59
  91. /// <summary>
  92. /// 输入设备的发射射线起点,优先级为Head/BTRight/BTLeft/GTRight/GTLeft
  93. /// </summary>
  94. public static GameObject Gazer {
  95. get {
  96. if(API_InputSystem_Head.Head != null) {
  97. return API_InputSystem_Head.Head.inputDeviceUIBase.model.lineIndicate.StartPoint.gameObject;
  98. } else if(API_InputSystem_Bluetooth.BTRight != null) {
  99. return API_InputSystem_Bluetooth.BTRight.inputDeviceUIBase.model.lineIndicate.StartPoint.gameObject;
  100. } else if(API_InputSystem_Bluetooth.BTLeft != null) {
  101. return API_InputSystem_Bluetooth.BTLeft.inputDeviceUIBase.model.lineIndicate.StartPoint.gameObject;
  102. } else if(API_InputSystem_Gesture26Dof.GTRight != null) {
  103. return API_InputSystem_Gesture26Dof.GTRight.inputDeviceUIBase.model.lineIndicate.StartPoint.gameObject;
  104. } else if(API_InputSystem_Gesture26Dof.GTLeft != null) {
  105. return API_InputSystem_Gesture26Dof.GTLeft.inputDeviceUIBase.model.lineIndicate.StartPoint.gameObject;
  106. }
  107. return null;
  108. }
  109. }
  110. ///API-No.60
  111. /// <summary>
  112. /// 输入设备的发射射线方向,优先级为Head/BTRight/BTLeft/GTRight/GTLeft
  113. /// </summary>
  114. public static Vector3 Normal {
  115. get {
  116. if(Gazer!=null) {
  117. return Gazer.transform.forward;
  118. }
  119. return Vector3.zero;
  120. }
  121. }
  122. ///API-No.61
  123. /// <summary>
  124. /// 输入设备Focus的位置,优先级为Head/BTRight/BTLeft/GTRight/GTLeft
  125. /// </summary>
  126. public static Vector3 Position {
  127. get {
  128. if(API_InputSystem_Head.Head != null) {
  129. return API_InputSystem_Head.GetHeadFocus.transform.position;
  130. } else if(API_InputSystem_Bluetooth.BTRight != null) {
  131. return API_InputSystem_Bluetooth.GetBTFocus(API_InputSystem_Bluetooth.BTType.Right).transform.position;
  132. } else if(API_InputSystem_Bluetooth.BTLeft != null) {
  133. return API_InputSystem_Bluetooth.GetBTFocus(API_InputSystem_Bluetooth.BTType.Left).transform.position;
  134. } else if(API_InputSystem_Gesture26Dof.GTRight != null) {
  135. return API_InputSystem_Gesture26Dof.GetGTFocus(API_InputSystem_Gesture26Dof.GestureType.Right).transform.position;
  136. } else if(API_InputSystem_Gesture26Dof.GTLeft != null) {
  137. return API_InputSystem_Gesture26Dof.GetGTFocus(API_InputSystem_Gesture26Dof.GestureType.Left).transform.position;
  138. }
  139. return Vector3.zero;
  140. }
  141. }
  142. ///API-No.62
  143. /// <summary>
  144. /// 获取当前的具体输入设备,优先级为Head/BTRight/BTLeft/GTRight/GTLeft
  145. /// </summary>
  146. public static InputDevicePartBase InputDeviceCurrent {
  147. get {
  148. if(API_InputSystem_Head.Head != null) {
  149. return API_InputSystem_Head.Head;
  150. } else if(API_InputSystem_Bluetooth.BTRight != null) {
  151. return API_InputSystem_Bluetooth.BTRight;
  152. } else if(API_InputSystem_Bluetooth.BTLeft != null) {
  153. return API_InputSystem_Bluetooth.BTLeft;
  154. } else if(API_InputSystem_Gesture26Dof.GTRight != null) {
  155. return API_InputSystem_Gesture26Dof.GTRight;
  156. } else if(API_InputSystem_Gesture26Dof.GTLeft != null) {
  157. return API_InputSystem_Gesture26Dof.GTLeft;
  158. }
  159. return null;
  160. }
  161. }
  162. }