API_InputSystem_Gesture26Dof.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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_Gesture26Dof {
  8. ///API-No.200
  9. /// <summary>
  10. /// 获取InputSystem支持的自由手势输入设备,自由手势输入设备包含二个Part,名曰:GTLeft,GTRight,也就是左手/右手
  11. /// </summary>
  12. /// <returns>null表示不支持或者InputSystem未初始好</returns>
  13. public static InputDevice26DofGesture Gesture26Dof {
  14. get {
  15. if(InputSystem.Instant) {
  16. return InputSystem.Instant.Gesture26Dof;
  17. }
  18. return null;
  19. }
  20. }
  21. public enum GestureType {
  22. Left=0,
  23. Right=1,
  24. }
  25. ///API-No.201
  26. /// <summary>
  27. /// 自由手势输入设备左手
  28. /// </summary>
  29. public static InputDevice26DofGesturePart GTLeft {
  30. get {
  31. if(Gesture26Dof && Gesture26Dof.InputDevice26DofGesturePartList[0]) {
  32. return Gesture26Dof.InputDevice26DofGesturePartList[0].inputDataBase.isVaild ? Gesture26Dof.InputDevice26DofGesturePartList[0] : null;
  33. }
  34. return null;
  35. }
  36. }
  37. ///API-No.202
  38. /// <summary>
  39. /// 自由手势输入设备右手
  40. /// </summary>
  41. public static InputDevice26DofGesturePart GTRight {
  42. get {
  43. if(Gesture26Dof && Gesture26Dof.InputDevice26DofGesturePartList[1]) {
  44. return Gesture26Dof.InputDevice26DofGesturePartList[1].inputDataBase.isVaild ? Gesture26Dof.InputDevice26DofGesturePartList[1] : null;
  45. }
  46. return null;
  47. }
  48. }
  49. ///API-No.203
  50. /// <summary>
  51. /// GTLeft/GTRight的手势数据,具体数据见handInfo
  52. /// </summary>
  53. /// <param name="type"></param>
  54. /// <returns></returns>
  55. public static handInfo GThandInfo(GestureType type = GestureType.Right) {
  56. if(GTLeft && type == GestureType.Left) {
  57. return GTLeft.inputData26DofGesture.handInfo;
  58. } else if(GTRight && type == GestureType.Right) {
  59. return GTRight.inputData26DofGesture.handInfo;
  60. }
  61. return null;
  62. }
  63. ///API-No.204
  64. /// <summary>
  65. /// GTLeft/GTRight 检测到碰撞信息集合,包含碰撞到的物体,数据等
  66. /// </summary>
  67. /// <param name="type"></param>
  68. /// <returns></returns>
  69. public static SCPointEventData GTPointerEventData(GestureType type = GestureType.Right) {
  70. if(GTLeft && type == GestureType.Left) {
  71. return GTLeft.inputDataBase.pointerEventData;
  72. } else if(GTRight && type == GestureType.Right) {
  73. return GTRight.inputDataBase.pointerEventData;
  74. }
  75. return null;
  76. }
  77. ///API-No.205
  78. /// <summary>
  79. /// GTLeft/GTRight 碰撞到Collider,若不为null,可以通过GTHitInfo获取碰撞信息,
  80. /// </summary>
  81. /// <param name="type"></param>
  82. /// <returns></returns>
  83. public static GameObject GTHitTarget(GestureType type = GestureType.Right) {
  84. if(GTPointerEventData(type) != null) {
  85. return GTPointerEventData(type).target;
  86. }
  87. return null;
  88. }
  89. ///API-No.206
  90. /// <summary>
  91. /// GTLeft/GTRight 碰撞信息
  92. /// </summary>
  93. /// <returns></returns>
  94. public static RaycastHit GTHitInfo(GestureType type = GestureType.Right) {
  95. if(GTPointerEventData(type) != null) {
  96. return GTPointerEventData(type).hitinfo;
  97. }
  98. return new RaycastHit();
  99. }
  100. ///API-No.207
  101. /// <summary>
  102. /// GTLeft/GTRight 拖拽的物体
  103. /// </summary>
  104. public static GameObject GTDragTarget(GestureType type = GestureType.Right) {
  105. if(GTPointerEventData(type) != null) {
  106. return GTPointerEventData(type).dragTarget;
  107. }
  108. return null;
  109. }
  110. ///API-No.208
  111. /// <summary>
  112. /// GTLeft/GTRight某个按键是否按下,当前帧有效,下帧复位,参考Input.GetKeyDown
  113. /// </summary>
  114. /// <param name="inputKeyCode">具体按键,GTLeft/GTRight支持Enter/Back/Function</param>
  115. /// <returns></returns>
  116. public static bool IsGTKeyDown(InputKeyCode inputKeyCode, GestureType type = GestureType.Right) {
  117. if(GTLeft && type == GestureType.Left) {
  118. return GTLeft.inputDataBase.GetKeyDown(inputKeyCode);
  119. } else if(GTRight && type == GestureType.Right) {
  120. return GTRight.inputDataBase.GetKeyDown(inputKeyCode);
  121. }
  122. return false;
  123. }
  124. ///API-No.209
  125. /// <summary>
  126. /// GTLeft/GTRight某个按键是否按下后松开,当前帧有效,下帧复位,参考Input.GetKeyUp
  127. /// </summary>
  128. /// <param name="inputKeyCode">具体按键,GTLeft/GTRight支持Enter/Back/Function</param>
  129. /// <returns></returns>
  130. public static bool IsGTKeyUp(InputKeyCode inputKeyCode, GestureType type = GestureType.Right) {
  131. if(GTLeft && type == GestureType.Left) {
  132. return GTLeft.inputDataBase.GetKeyUp(inputKeyCode);
  133. } else if(GTRight && type == GestureType.Right) {
  134. return GTRight.inputDataBase.GetKeyUp(inputKeyCode);
  135. }
  136. return false;
  137. }
  138. ///API-No.210
  139. /// <summary>
  140. /// GTLeft/GTRight某个按键的状态信息,当前帧有效,下帧复位
  141. /// </summary>
  142. /// <param name="inputKeyCode">具体按键,GTLeft/GTRight支持Enter/Back/Function</param>
  143. /// <returns></returns>
  144. public static InputKeyState GTKeyState(InputKeyCode inputKeyCode, GestureType type = GestureType.Right) {
  145. if(GTLeft && type == GestureType.Left) {
  146. return GTLeft.inputDataBase.GetKeyState(inputKeyCode);
  147. } else if(GTRight && type == GestureType.Right) {
  148. return GTRight.inputDataBase.GetKeyState(inputKeyCode);
  149. }
  150. return InputKeyState.Null;
  151. }
  152. ///API-No.211
  153. /// <summary>
  154. /// GTLeft/GTRight某个按键的实时状态,参考Input.GetKey
  155. /// </summary>
  156. /// <param name="inputKeyCode">具体按键,GTLeft/GTRight支持Enter/Back/Function</param>
  157. /// <returns></returns>
  158. public static InputKeyState GTKeyCurrentState(InputKeyCode inputKeyCode, GestureType type = GestureType.Right) {
  159. if(GTLeft && type == GestureType.Left) {
  160. return GTLeft.inputDataBase.GetKeyCurrentState(inputKeyCode);
  161. } else if(GTRight && type == GestureType.Right) {
  162. return GTRight.inputDataBase.GetKeyCurrentState(inputKeyCode);
  163. }
  164. return InputKeyState.Null;
  165. }
  166. ///API-No.212
  167. /// <summary>
  168. /// GTLeft/GTRight发送一个按键,注意,发送按键至少需发送一个Down,然后再发送一个Up,此API模拟按键按下动作
  169. /// </summary>
  170. /// <param name="inputKeyCode">具体按键</param>
  171. /// <param name="inputKeyState">按键的状态</param>
  172. public static void GTKeyAddKey(InputKeyCode inputKeyCode, InputKeyState inputKeyState, GestureType type = GestureType.Right) {
  173. if(GTLeft && type == GestureType.Left) {
  174. GTLeft.inputDataBase.InputDataAddKey(inputKeyCode, inputKeyState);
  175. } else if(GTRight && type == GestureType.Right) {
  176. GTRight.inputDataBase.InputDataAddKey(inputKeyCode, inputKeyState);
  177. }
  178. }
  179. ///API-No.213
  180. /// <summary>
  181. /// GTLeft/GTRight设置可检测Collider的范围半径 默认50米
  182. /// </summary>
  183. /// <param name="distance">单位米</param>
  184. public static void SetGTRayCastDistance(float distance, GestureType type = GestureType.Right) {
  185. if(GTLeft && type == GestureType.Left) {
  186. GTLeft.inputDeviceTargetDetecterBase.MaxRaycastRange = distance;
  187. } else if(GTRight && type == GestureType.Right) {
  188. GTRight.inputDeviceTargetDetecterBase.MaxRaycastRange = distance;
  189. }
  190. }
  191. ///API-No.214
  192. /// <summary>
  193. /// GTLeft/GTRight设置可见光束的长度 默认3米
  194. /// </summary>
  195. /// <param name="distance">单位米</param>
  196. public static void SetGTEndPointerDistance(float distance, GestureType type = GestureType.Right) {
  197. if(GTLeft && type == GestureType.Left) {
  198. GTLeft.inputDeviceTargetDetecterBase.MaxEndPointRange = distance;
  199. } else if(GTRight && type == GestureType.Right) {
  200. GTRight.inputDeviceTargetDetecterBase.MaxEndPointRange = distance;
  201. }
  202. }
  203. ///API-No.215
  204. /// <summary>
  205. /// GTLeft/GTRight获取光束终点的Focus对象
  206. /// </summary>
  207. /// <param name="distance">单位米</param>
  208. public static Focus GetGTFocus(GestureType type = GestureType.Right) {
  209. if(GTLeft && type == GestureType.Left) {
  210. return GTLeft.inputDeviceUIBase.model.lineIndicate.focus;
  211. } else if(GTRight && type == GestureType.Right) {
  212. return GTRight.inputDeviceUIBase.model.lineIndicate.focus;
  213. }
  214. return null;
  215. }
  216. ///API-No.216
  217. /// <summary>
  218. /// GTLeft/GTRight获取光束
  219. /// </summary>
  220. /// <param name="distance">单位米</param>
  221. public static LineRenderer GetGTLine(GestureType type = GestureType.Right) {
  222. if(GTLeft && type == GestureType.Left) {
  223. return GTLeft.inputDeviceUIBase.model.lineIndicate.line;
  224. } else if(GTRight && type == GestureType.Right) {
  225. return GTRight.inputDeviceUIBase.model.lineIndicate.line;
  226. }
  227. return null;
  228. }
  229. ///API-No.217
  230. /// <summary>
  231. /// 开启GTLeft
  232. /// </summary>
  233. /// <param name="type"></param>
  234. public static void EnableGT(GestureType type = GestureType.Right) {
  235. if(Gesture26Dof && type == GestureType.Left) {
  236. Gesture26Dof.LeftHandOpen = true;
  237. } else if(Gesture26Dof && type == GestureType.Right) {
  238. Gesture26Dof.RightHandOpen = true;
  239. }
  240. }
  241. ///API-No.218
  242. /// <summary>
  243. /// 关闭GTLeft
  244. /// </summary>
  245. /// <param name="type"></param>
  246. public static void DisableableGT(GestureType type = GestureType.Right) {
  247. if(Gesture26Dof && type == GestureType.Left) {
  248. Gesture26Dof.LeftHandOpen = false;
  249. } else if(Gesture26Dof && type == GestureType.Right) {
  250. Gesture26Dof.RightHandOpen = false;
  251. }
  252. }
  253. ///API-No.219
  254. /// <summary>
  255. /// 获取手势游戏对象,具体见fingerUI
  256. /// </summary>
  257. /// <param name="type"></param>
  258. /// <returns></returns>
  259. public static Model26DofGesture.fingerUI[] GetFingerUI(GestureType type = GestureType.Right) {
  260. if(GTLeft && type == GestureType.Left) {
  261. return GTLeft.inputDevice26DofGestureUI.model26DofGesture.fingers;
  262. } else if(GTRight && type == GestureType.Right) {
  263. return GTRight.inputDevice26DofGestureUI.model26DofGesture.fingers;
  264. }
  265. return null;
  266. }
  267. }