API_InputSystem_Bluetooth.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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_Bluetooth {
  8. ///API-No.150
  9. /// <summary>
  10. /// 获取InputSystem支持的手柄输入设备,手柄输入设备包含二个Part,名曰:BTRight,BTLeft,也就是第一个手柄和第二个手柄
  11. /// </summary>
  12. /// <returns>null表示不支持或者InputSystem未初始好</returns>
  13. public static InputDeviceHandShank BTDevice {
  14. get {
  15. if(InputSystem.Instant) {
  16. return InputSystem.Instant.HandShank;
  17. }
  18. return null;
  19. }
  20. }
  21. ///API-No.151
  22. /// <summary>
  23. /// 手柄输入设备连接的第一个手柄
  24. /// </summary>
  25. public static InputDeviceHandShankPart BTRight {
  26. get {
  27. if(BTDevice && BTDevice.inputDeviceHandShankPartList[0]) {
  28. return BTDevice.inputDeviceHandShankPartList[0].inputDataBase.isVaild ? BTDevice.inputDeviceHandShankPartList[0] : null;
  29. }
  30. return null;
  31. }
  32. }
  33. ///API-No.152
  34. /// <summary>
  35. /// 手柄输入设备连接的第二个手柄
  36. /// </summary>
  37. public static InputDeviceHandShankPart BTLeft {
  38. get {
  39. if(BTDevice && BTDevice.inputDeviceHandShankPartList[1]) {
  40. return BTDevice.inputDeviceHandShankPartList[1].inputDataBase.isVaild ? BTDevice.inputDeviceHandShankPartList[1] : null;
  41. }
  42. return null;
  43. }
  44. }
  45. public enum BTType {
  46. Left,
  47. Right
  48. }
  49. ///API-No.153
  50. /// <summary>
  51. /// BTRight/BTLeft的四元素,全局坐标
  52. /// </summary>
  53. /// <param name="type">右手柄 BTRight / 左手柄 BTLeft</param>
  54. /// <returns></returns>
  55. public static Quaternion BTRotation(BTType type = BTType.Right) {
  56. if(BTRight && type == BTType.Right) {
  57. return BTRight.inputDataHandShank.rotation;
  58. } else if(BTLeft && type == BTType.Left) {
  59. return BTLeft.inputDataHandShank.rotation;
  60. }
  61. return Quaternion.identity;
  62. }
  63. ///API-No.154
  64. /// <summary>
  65. /// BTRight/BTLeft的四元素,全局坐标
  66. /// </summary>
  67. /// <param name="type">右手柄 BTRight / 左手柄 BTLeft</param>
  68. /// <returns></returns>
  69. public static Vector3 BTPosition(BTType type = BTType.Right) {
  70. if(BTRight && type == BTType.Right) {
  71. return BTRight.inputDataHandShank.position;
  72. } else if(BTLeft && type == BTType.Left) {
  73. return BTLeft.inputDataHandShank.position;
  74. }
  75. return Vector3.zero;
  76. }
  77. ///API-No.155
  78. /// <summary>
  79. /// BTRight/BTLeft 的触摸板是否触摸
  80. /// </summary>
  81. /// <param name="type">右手柄 BTRight / 左手柄 BTLeft</param>
  82. /// <returns>ture表示被触摸,反之</returns>
  83. public static bool IsBTTpTouch(BTType type = BTType.Right) {
  84. if(BTRight && type == BTType.Right) {
  85. return BTRight.inputDataHandShank.isTpTouch;
  86. } else if(BTLeft && type == BTType.Left) {
  87. return BTLeft.inputDataHandShank.isTpTouch;
  88. }
  89. return false;
  90. }
  91. ///API-No.156
  92. /// <summary>
  93. /// BTRight/BTLeft 的触摸板触摸数据
  94. /// </summary>
  95. /// <param name="type">右手柄 BTRight / 左手柄 BTLeft</param>
  96. /// <returns></returns>
  97. public static Vector2 BTTpTouchInfo(BTType type = BTType.Right) {
  98. if(BTRight && type == BTType.Right) {
  99. return BTRight.inputDataHandShank.tpPosition;
  100. } else if(BTLeft && type == BTType.Left) {
  101. return BTLeft.inputDataHandShank.tpPosition;
  102. }
  103. return Vector2.zero;
  104. }
  105. ///API-No.157
  106. /// <summary>
  107. /// BTRight/BTLeft 的触摸板触摸数据
  108. /// </summary>
  109. /// <param name="type">右手柄 BTRight / 左手柄 BTLeft</param>
  110. /// <returns></returns>
  111. public static string BTName(BTType type = BTType.Right) {
  112. if(BTRight && type == BTType.Right) {
  113. return BTRight.inputDataHandShank.blueToothName;
  114. } else if(BTLeft && type == BTType.Left) {
  115. return BTLeft.inputDataHandShank.blueToothName;
  116. }
  117. return "";
  118. }
  119. ///API-No.158
  120. /// <summary>
  121. /// BTRight/BTLeft 检测到碰撞信息集合,包含碰撞到的物体,数据等
  122. /// </summary>
  123. /// <param name="type">右手柄 BTRight / 左手柄 BTLeft</param>
  124. /// <returns></returns>
  125. public static SCPointEventData BTPointerEventData(BTType type = BTType.Right) {
  126. if(BTRight && type == BTType.Right) {
  127. return BTRight.inputDataBase.pointerEventData;
  128. } else if(BTLeft && type == BTType.Left) {
  129. return BTLeft.inputDataBase.pointerEventData;
  130. }
  131. return null;
  132. }
  133. ///API-No.159
  134. /// <summary>
  135. /// BTRight/BTLeft 碰撞到Collider,若不为null,可以通过BTHitInfo获取碰撞信息,
  136. /// </summary>
  137. /// <param name="type">右手柄 BTRight / 左手柄 BTLeft</param>
  138. /// <returns></returns>
  139. public static GameObject BTHitTarget(BTType type = BTType.Right) {
  140. if(BTPointerEventData(type) != null) {
  141. return BTPointerEventData(type).target;
  142. }
  143. return null;
  144. }
  145. ///API-No.160
  146. /// <summary>
  147. /// BTRight/BTLeft 碰撞信息
  148. /// </summary>
  149. /// <returns></returns>
  150. public static RaycastHit BTHitInfo(BTType type = BTType.Right) {
  151. if(BTPointerEventData(type) != null) {
  152. return BTPointerEventData(type).hitinfo;
  153. }
  154. return new RaycastHit();
  155. }
  156. ///API-No.161
  157. /// <summary>
  158. /// BTRight/BTLeft 拖拽的物体
  159. /// </summary>
  160. public static GameObject BTDragTarget(BTType type = BTType.Right) {
  161. if(BTPointerEventData(type) != null) {
  162. return BTPointerEventData(type).dragTarget;
  163. }
  164. return null;
  165. }
  166. ///API-No.162
  167. /// <summary>
  168. /// BTRight/BTLeft某个按键是否按下,当前帧有效,下帧复位,参考Input.GetKeyDown
  169. /// </summary>
  170. /// <param name="inputKeyCode">具体按键,BTRight/BTLeft支持Enter/Back/Function</param>
  171. /// <returns></returns>
  172. public static bool IsBTKeyDown(InputKeyCode inputKeyCode, BTType type = BTType.Right) {
  173. if(BTRight && type == BTType.Right) {
  174. return BTRight.inputDataBase.GetKeyDown(inputKeyCode);
  175. } else if(BTLeft && type == BTType.Left) {
  176. return BTLeft.inputDataBase.GetKeyDown(inputKeyCode);
  177. }
  178. return false;
  179. }
  180. ///API-No.163
  181. /// <summary>
  182. /// BTRight/BTLeft某个按键是否按下后松开,当前帧有效,下帧复位,参考Input.GetKeyUp
  183. /// </summary>
  184. /// <param name="inputKeyCode">具体按键,BTRight/BTLeft支持Enter/Back/Function</param>
  185. /// <returns></returns>
  186. public static bool IsBTKeyUp(InputKeyCode inputKeyCode, BTType type = BTType.Right) {
  187. if(BTRight && type == BTType.Right) {
  188. return BTRight.inputDataBase.GetKeyUp(inputKeyCode);
  189. } else if(BTLeft && type == BTType.Left) {
  190. return BTLeft.inputDataBase.GetKeyUp(inputKeyCode);
  191. }
  192. return false;
  193. }
  194. ///API-No.164
  195. /// <summary>
  196. /// BTRight/BTLeft某个按键的状态信息,当前帧有效,下帧复位
  197. /// </summary>
  198. /// <param name="inputKeyCode">具体按键,BTRight/BTLeft支持Enter/Back/Function</param>
  199. /// <returns></returns>
  200. public static InputKeyState BTKeyState(InputKeyCode inputKeyCode, BTType type = BTType.Right) {
  201. if(BTRight && type == BTType.Right) {
  202. return BTRight.inputDataBase.GetKeyState(inputKeyCode);
  203. } else if(BTLeft && type == BTType.Left) {
  204. return BTLeft.inputDataBase.GetKeyState(inputKeyCode);
  205. }
  206. return InputKeyState.Null;
  207. }
  208. ///API-No.165
  209. /// <summary>
  210. /// BTRight/BTLeft某个按键的实时状态,参考Input.GetKey
  211. /// </summary>
  212. /// <param name="inputKeyCode">具体按键,BTRight/BTLeft支持Enter/Back/Function</param>
  213. /// <returns></returns>
  214. public static InputKeyState BTKeyCurrentState(InputKeyCode inputKeyCode, BTType type = BTType.Right) {
  215. if(BTRight && type == BTType.Right) {
  216. return BTRight.inputDataBase.GetKeyCurrentState(inputKeyCode);
  217. } else if(BTLeft && type == BTType.Left) {
  218. return BTLeft.inputDataBase.GetKeyCurrentState(inputKeyCode);
  219. }
  220. return InputKeyState.Null;
  221. }
  222. ///API-No.166
  223. /// <summary>
  224. /// BTRight/BTLeft发送一个按键,注意,发送按键至少需发送一个Down,然后再发送一个Up,此API模拟按键按下动作
  225. /// </summary>
  226. /// <param name="inputKeyCode">具体按键</param>
  227. /// <param name="inputKeyState">按键的状态</param>
  228. public static void BTKeyAddKey(InputKeyCode inputKeyCode, InputKeyState inputKeyState, BTType type = BTType.Right) {
  229. if(BTRight && type == BTType.Right) {
  230. BTRight.inputDataBase.InputDataAddKey(inputKeyCode, inputKeyState);
  231. } else if(BTLeft && type == BTType.Left) {
  232. BTLeft.inputDataBase.InputDataAddKey(inputKeyCode, inputKeyState);
  233. }
  234. }
  235. ///API-No.167
  236. /// <summary>
  237. /// BTRight/BTLeft设置可检测Collider的范围半径 默认50米
  238. /// </summary>
  239. /// <param name="distance">单位米</param>
  240. public static void SetBTRayCastDistance(float distance, BTType type = BTType.Right) {
  241. if(BTRight && type == BTType.Right) {
  242. BTRight.inputDeviceTargetDetecterBase.MaxRaycastRange = distance;
  243. } else if(BTLeft && type == BTType.Left) {
  244. BTLeft.inputDeviceTargetDetecterBase.MaxRaycastRange = distance;
  245. }
  246. }
  247. ///API-No.168
  248. /// <summary>
  249. /// BTRight/BTLeft设置可见光束的长度 默认3米
  250. /// </summary>
  251. /// <param name="distance">单位米</param>
  252. public static void SetBTEndPointerDistance(float distance, BTType type = BTType.Right) {
  253. if(BTRight && type == BTType.Right) {
  254. BTRight.inputDeviceTargetDetecterBase.MaxEndPointRange = distance;
  255. } else if(BTLeft && type == BTType.Left) {
  256. BTLeft.inputDeviceTargetDetecterBase.MaxEndPointRange = distance;
  257. }
  258. }
  259. ///API-No.169
  260. /// <summary>
  261. /// BTRight/BTLeft获取光束终点的Focus对象
  262. /// </summary>
  263. /// <param name="distance">单位米</param>
  264. public static Focus GetBTFocus(BTType type = BTType.Right) {
  265. if(BTRight && type == BTType.Right) {
  266. return BTRight.inputDeviceUIBase.model.lineIndicate.focus;
  267. } else if(BTLeft && type == BTType.Left) {
  268. return BTLeft.inputDeviceUIBase.model.lineIndicate.focus;
  269. }
  270. return null;
  271. }
  272. ///API-No.170
  273. /// <summary>
  274. /// BTRight/BTLeft获取光束
  275. /// </summary>
  276. /// <param name="distance">单位米</param>
  277. public static LineRenderer GetBTLine(BTType type = BTType.Right) {
  278. if(BTRight && type == BTType.Right) {
  279. return BTRight.inputDeviceUIBase.model.lineIndicate.line;
  280. } else if(BTLeft && type == BTType.Left) {
  281. return BTLeft.inputDeviceUIBase.model.lineIndicate.line;
  282. }
  283. return null;
  284. }
  285. ///API-No.171
  286. /// <summary>
  287. /// 开启BTRight/BTLeft
  288. /// </summary>
  289. /// <param name="type"></param>
  290. public static void EnableBT(BTType type = BTType.Right) {
  291. if(BTDevice && type == BTType.Right) {
  292. BTDevice.OneHandShankOpen = true;
  293. } else if(BTDevice && type == BTType.Left) {
  294. BTDevice.TwoHandShankOpen = true;
  295. }
  296. }
  297. ///API-No.172
  298. /// <summary>
  299. /// 关闭BTRight/BTLeft
  300. /// </summary>
  301. /// <param name="type"></param>
  302. public static void DisableableBT(BTType type = BTType.Right) {
  303. if(BTDevice && type == BTType.Right) {
  304. BTDevice.OneHandShankOpen = false;
  305. } else if(BTDevice && type == BTType.Left) {
  306. BTDevice.TwoHandShankOpen = false;
  307. }
  308. }
  309. }