API_InputSystem_Head.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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_Head {
  8. ///API-No.100
  9. /// <summary>
  10. /// 获取InputSystem支持的头部输入设备,头部输入设备包含一个Part,名曰:Head
  11. /// </summary>
  12. /// <returns>null表示不支持或者InputSystem未初始好</returns>
  13. public static InputDeviceHead HeadDevice {
  14. get {
  15. if(InputSystem.Instant) {
  16. return InputSystem.Instant.Head;
  17. }
  18. return null;
  19. }
  20. }
  21. ///API-No.101
  22. /// <summary>
  23. /// 头部输入设备包含的Part
  24. /// </summary>
  25. public static InputDeviceHeadPart Head {
  26. get {
  27. if(HeadDevice && HeadDevice.inputDeviceHeadPartList[0]) {
  28. return HeadDevice.inputDeviceHeadPartList[0].inputDataBase.isVaild ? HeadDevice.inputDeviceHeadPartList[0] : null;
  29. }
  30. return null;
  31. }
  32. }
  33. ///API-No.102
  34. /// <summary>
  35. /// Head的欧拉角,全局坐标
  36. /// </summary>
  37. public static Vector3 HeadEulerAngles {
  38. get {
  39. if(Head) {
  40. return Head.inputDataHead.rotation;
  41. }
  42. return Vector3.zero;
  43. }
  44. }
  45. ///API-No.103
  46. /// <summary>
  47. /// Head的位置,全局坐标
  48. /// </summary>
  49. public static Vector3 HeadPosition {
  50. get {
  51. if(Head) {
  52. return Head.inputDataHead.position;
  53. }
  54. return Vector3.zero;
  55. }
  56. }
  57. ///API-No.104
  58. /// <summary>
  59. /// Head的检测到碰撞信息集合,包含碰撞到的物体,数据等
  60. /// </summary>
  61. public static SCPointEventData HeadPointerEventData {
  62. get {
  63. if(Head) {
  64. return Head.inputDataBase.pointerEventData;
  65. }
  66. return null;
  67. }
  68. }
  69. ///API-No.105
  70. /// <summary>
  71. /// Head碰撞到Collider,若不为null,可以通过HeadHitInfo获取碰撞信息,
  72. /// </summary>
  73. public static GameObject HeadHitTarget {
  74. get {
  75. if(HeadPointerEventData != null) {
  76. return HeadPointerEventData.target;
  77. }
  78. return null;
  79. }
  80. }
  81. ///API-No.106
  82. /// <summary>
  83. /// Head碰撞信息
  84. /// </summary>
  85. /// <returns></returns>
  86. public static RaycastHit HeadHitInfo {
  87. get{
  88. if(HeadPointerEventData != null) {
  89. return HeadPointerEventData.hitinfo;
  90. }
  91. return new RaycastHit();
  92. }
  93. }
  94. ///API-No.107
  95. /// <summary>
  96. /// Head拖拽的物体
  97. /// </summary>
  98. public static GameObject HeadDragTarget {
  99. get {
  100. if(HeadPointerEventData != null) {
  101. return HeadPointerEventData.dragTarget;
  102. }
  103. return null;
  104. }
  105. }
  106. ///API-No.108
  107. /// <summary>
  108. /// Head某个按键是否按下,当前帧有效,下帧复位,参考Input.GetKeyDown
  109. /// </summary>
  110. /// <param name="inputKeyCode">具体按键,Head支持Enter/Back</param>
  111. /// <returns></returns>
  112. public static bool IsHeadKeyDown(InputKeyCode inputKeyCode) {
  113. if(Head) {
  114. return Head.inputDataBase.GetKeyDown(inputKeyCode);
  115. }
  116. return false;
  117. }
  118. ///API-No.109
  119. /// <summary>
  120. /// Head某个按键是否按下后松开,当前帧有效,下帧复位,参考Input.GetKeyUp
  121. /// </summary>
  122. /// <param name="inputKeyCode">具体按键,Head支持Enter/Back</param>
  123. /// <returns></returns>
  124. public static bool IsHeadKeyUp(InputKeyCode inputKeyCode) {
  125. if(Head) {
  126. return Head.inputDataBase.GetKeyUp(inputKeyCode);
  127. }
  128. return false;
  129. }
  130. ///API-No.110
  131. /// <summary>
  132. /// Head某个按键的状态信息,当前帧有效,下帧复位
  133. /// </summary>
  134. /// <param name="inputKeyCode">具体按键,Head支持Enter/Back</param>
  135. /// <returns></returns>
  136. public static InputKeyState HeadKeyState(InputKeyCode inputKeyCode) {
  137. if(Head) {
  138. return Head.inputDataBase.GetKeyState(inputKeyCode);
  139. }
  140. return InputKeyState.Null;
  141. }
  142. ///API-No.111
  143. /// <summary>
  144. /// Head某个按键的实时状态,参考Input.GetKey
  145. /// </summary>
  146. /// <param name="inputKeyCode">具体按键,Head支持Enter/Back</param>
  147. /// <returns></returns>
  148. public static InputKeyState HeadKeyCurrentState(InputKeyCode inputKeyCode) {
  149. if(Head) {
  150. return Head.inputDataBase.GetKeyCurrentState(inputKeyCode);
  151. }
  152. return InputKeyState.Null;
  153. }
  154. ///API-No.112
  155. /// <summary>
  156. /// 给Head发送一个按键,注意,发送按键至少需发送一个Down,然后再发送一个Up,此API模拟按键按下动作
  157. /// </summary>
  158. /// <param name="inputKeyCode">具体按键</param>
  159. /// <param name="inputKeyState">按键的状态</param>
  160. public static void HeadAddKey(InputKeyCode inputKeyCode, InputKeyState inputKeyState) {
  161. if(Head) {
  162. Head.inputDataBase.InputDataAddKey(inputKeyCode, inputKeyState);
  163. }
  164. }
  165. ///API-No.113
  166. /// <summary>
  167. /// 设置可检测Collider的范围半径 默认50米
  168. /// </summary>
  169. /// <param name="distance">单位米</param>
  170. public static void SetHeadRayCastDistance(float distance) {
  171. if(Head && distance > 0) {
  172. Head.inputDeviceTargetDetecterBase.MaxRaycastRange = distance;
  173. }
  174. }
  175. ///API-No.114
  176. /// <summary>
  177. /// 设置可见Focus的长度 默认3米
  178. /// </summary>
  179. /// <param name="distance">单位米</param>
  180. public static void SetHeadEndPointerDistance(float distance) {
  181. if(Head && distance > 0) {
  182. Head.inputDeviceTargetDetecterBase.MaxEndPointRange = distance;
  183. }
  184. }
  185. ///API-No.115
  186. /// <summary>
  187. /// 获取Head光束终点的Focus对象
  188. /// </summary>
  189. public static Focus GetHeadFocus {
  190. get {
  191. if(Head) {
  192. return Head.inputDeviceUIBase.model.lineIndicate.focus;
  193. }
  194. return null;
  195. }
  196. }
  197. }