NxrInput.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. using NibiruTask;
  2. using UnityEngine;
  3. using System;
  4. namespace Nxr.Internal
  5. {
  6. /// <summary>
  7. ///
  8. /// </summary>
  9. public class NxrInput
  10. {
  11. const int MAX_INDEX = 256;
  12. private static int[] KeyStateHMD = new int[MAX_INDEX];
  13. private static int[] KeyStateControllerLeft = new int[MAX_INDEX];
  14. private static int[] KeyStateControllerRight = new int[MAX_INDEX];
  15. private static int[] KeyStateController3DOF = new int[MAX_INDEX];
  16. private static int[] KeyStateControllerNOLO_Left = new int[MAX_INDEX];
  17. private static int[] KeyStateControllerNOLO_Right = new int[MAX_INDEX];
  18. private static int[] KeyStateHMD_Pre = new int[MAX_INDEX];
  19. private static int[] KeyStateControllerLeft_Pre = new int[MAX_INDEX];
  20. private static int[] KeyStateControllerRight_Pre = new int[MAX_INDEX];
  21. private static int[] KeyStateController3DOF_Pre = new int[MAX_INDEX];
  22. private static int[] KeyStateControllerNOLO_Left_Pre = new int[MAX_INDEX];
  23. private static int[] KeyStateControllerNOLO_Right_Pre = new int[MAX_INDEX];
  24. public NxrInput()
  25. {
  26. Reset();
  27. }
  28. public void Reset()
  29. {
  30. for (int i = 0; i < MAX_INDEX; i++)
  31. {
  32. // 默认up
  33. KeyStateHMD[i] = CKeyEvent.ACTION_UP;
  34. KeyStateControllerRight[i] = CKeyEvent.ACTION_UP;
  35. KeyStateControllerLeft[i] = CKeyEvent.ACTION_UP;
  36. KeyStateController3DOF[i] = CKeyEvent.ACTION_UP;
  37. KeyStateControllerNOLO_Left[i] = CKeyEvent.ACTION_UP;
  38. KeyStateControllerNOLO_Right[i] = CKeyEvent.ACTION_UP;
  39. KeyStateHMD_Pre[i] = CKeyEvent.ACTION_UP;
  40. KeyStateControllerRight_Pre[i] = CKeyEvent.ACTION_UP;
  41. KeyStateControllerLeft_Pre[i] = CKeyEvent.ACTION_UP;
  42. KeyStateController3DOF_Pre[i] = CKeyEvent.ACTION_UP;
  43. KeyStateControllerNOLO_Left_Pre[i] = CKeyEvent.ACTION_UP;
  44. KeyStateControllerNOLO_Right_Pre[i] = CKeyEvent.ACTION_UP;
  45. }
  46. }
  47. public void OnChangeKeyEvent(int keyCode, int keyAction)
  48. {
  49. KeyStateHMD[CKeyEvent.KEYCODE_VOLUME_DOWN] = CKeyEvent.ACTION_DOWN;
  50. }
  51. // One Frame Update
  52. public void Process()
  53. {
  54. //when ime show unity is still running, disable input process
  55. if (TouchScreenKeyboard.visible)
  56. {
  57. NxrViewer.Instance.Triggered = false;
  58. return;
  59. }
  60. Array.Copy(KeyStateHMD, KeyStateHMD_Pre, MAX_INDEX);
  61. Array.Copy(KeyStateControllerLeft, KeyStateControllerLeft_Pre, MAX_INDEX);
  62. Array.Copy(KeyStateControllerRight, KeyStateControllerRight_Pre, MAX_INDEX);
  63. bool dpadCenterDown = Input.GetKey(KeyCode.JoystickButton0) || Input.GetKey((KeyCode) 10) ||
  64. Input.GetMouseButtonDown(0);
  65. #if Unity_2018_4_30
  66. dpadCenterDown = Input.GetKey(KeyCode.JoystickButton0) || Input.GetKey((KeyCode) 10) || Input.GetKey(KeyCode.Return)
  67. Input.GetMouseButtonDown(0);
  68. #endif
  69. bool backDown = Input.GetKey(KeyCode.Escape);
  70. bool dpadLeftDown = Input.GetKey(KeyCode.LeftArrow);
  71. bool dpadRightDown = Input.GetKey(KeyCode.RightArrow);
  72. bool dpadUpDown = Input.GetKey(KeyCode.UpArrow);
  73. bool dpadDownDown = Input.GetKey(KeyCode.DownArrow);
  74. // 功能按键nf1/nf2
  75. bool nf1Down = Input.GetKey(KeyCode.Joystick6Button1);
  76. bool nf2Down = Input.GetKey(KeyCode.Joystick6Button2);
  77. bool dpadCenterUp = false;
  78. if ((!InteractionManager.IsControllerConnected() && !ControllerAndroid.isQuatConn() &&
  79. !ControllerAndroid.IsNoloConn()) || Application.isEditor)
  80. {
  81. dpadCenterUp = Input.GetKeyUp(KeyCode.JoystickButton0) || Input.GetKeyUp((KeyCode) 10) ||
  82. Input.GetMouseButtonUp(0);
  83. }
  84. // 模拟一体机按键: WASD 上左下右,空格返回,回车确定
  85. if (Application.isEditor)
  86. {
  87. dpadCenterDown = Input.GetKey(KeyCode.Return) || Input.GetMouseButton(0);
  88. dpadLeftDown = Input.GetKey(KeyCode.A);
  89. dpadRightDown = Input.GetKey(KeyCode.D);
  90. dpadUpDown = Input.GetKey(KeyCode.W);
  91. dpadDownDown = Input.GetKey(KeyCode.S);
  92. backDown = Input.GetKey(KeyCode.Space);
  93. }
  94. if (nf1Down)
  95. {
  96. KeyStateHMD[CKeyEvent.KEYCODE_NF_1] = CKeyEvent.ACTION_DOWN;
  97. }
  98. else
  99. {
  100. KeyStateHMD[CKeyEvent.KEYCODE_NF_1] = CKeyEvent.ACTION_UP;
  101. }
  102. if (nf2Down)
  103. {
  104. KeyStateHMD[CKeyEvent.KEYCODE_NF_2] = CKeyEvent.ACTION_DOWN;
  105. }
  106. else
  107. {
  108. KeyStateHMD[CKeyEvent.KEYCODE_NF_2] = CKeyEvent.ACTION_UP;
  109. }
  110. if (backDown)
  111. {
  112. KeyStateHMD[CKeyEvent.KEYCODE_BACK] = CKeyEvent.ACTION_DOWN;
  113. }
  114. else
  115. {
  116. KeyStateHMD[CKeyEvent.KEYCODE_BACK] = CKeyEvent.ACTION_UP;
  117. }
  118. if (dpadCenterUp)
  119. {
  120. NxrViewer.Instance.Triggered = true;
  121. }
  122. if (dpadCenterDown)
  123. {
  124. KeyStateHMD[CKeyEvent.KEYCODE_DPAD_CENTER] = CKeyEvent.ACTION_DOWN;
  125. }
  126. else
  127. {
  128. KeyStateHMD[CKeyEvent.KEYCODE_DPAD_CENTER] = CKeyEvent.ACTION_UP;
  129. }
  130. if (dpadLeftDown)
  131. {
  132. KeyStateHMD[CKeyEvent.KEYCODE_DPAD_LEFT] = CKeyEvent.ACTION_DOWN;
  133. }
  134. else
  135. {
  136. KeyStateHMD[CKeyEvent.KEYCODE_DPAD_LEFT] = CKeyEvent.ACTION_UP;
  137. }
  138. if (dpadRightDown)
  139. {
  140. KeyStateHMD[CKeyEvent.KEYCODE_DPAD_RIGHT] = CKeyEvent.ACTION_DOWN;
  141. }
  142. else
  143. {
  144. KeyStateHMD[CKeyEvent.KEYCODE_DPAD_RIGHT] = CKeyEvent.ACTION_UP;
  145. }
  146. if (dpadUpDown)
  147. {
  148. KeyStateHMD[CKeyEvent.KEYCODE_DPAD_UP] = CKeyEvent.ACTION_DOWN;
  149. }
  150. else
  151. {
  152. KeyStateHMD[CKeyEvent.KEYCODE_DPAD_UP] = CKeyEvent.ACTION_UP;
  153. }
  154. if (dpadDownDown)
  155. {
  156. KeyStateHMD[CKeyEvent.KEYCODE_DPAD_DOWN] = CKeyEvent.ACTION_DOWN;
  157. }
  158. else
  159. {
  160. KeyStateHMD[CKeyEvent.KEYCODE_DPAD_DOWN] = CKeyEvent.ACTION_UP;
  161. }
  162. // 3Dof/6Dof Controller
  163. if (InteractionManager.IsControllerConnected())
  164. {
  165. //3DOF
  166. Array.Copy(KeyStateController3DOF, KeyStateController3DOF_Pre, MAX_INDEX);
  167. int[] keyAction = InteractionManager.GetKeyAction();
  168. KeyStateController3DOF = keyAction;
  169. // NOLO
  170. if (InteractionManager.IsSixDofController)
  171. {
  172. Array.Copy(KeyStateControllerNOLO_Left, KeyStateControllerNOLO_Left_Pre, MAX_INDEX);
  173. Array.Copy(KeyStateControllerNOLO_Right, KeyStateControllerNOLO_Right_Pre, MAX_INDEX);
  174. int[] keyActionLeft =
  175. InteractionManager.GetKeyAction((int) InteractionManager.NACTION_HAND_TYPE.HAND_LEFT);
  176. int[] keyActionRight =
  177. InteractionManager.GetKeyAction((int) InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT);
  178. KeyStateControllerNOLO_Left = keyActionLeft;
  179. KeyStateControllerNOLO_Right = keyActionRight;
  180. }
  181. }
  182. else if (ControllerAndroid.isQuatConn() || ControllerAndroid.IsNoloConn())
  183. {
  184. // 交互库Close
  185. Array.Copy(KeyStateController3DOF, KeyStateController3DOF_Pre, MAX_INDEX);
  186. int[] keyAction = NibiruTaskApi.GetKeyAction();
  187. KeyStateController3DOF = keyAction;
  188. // type, action, x, y
  189. float[] touchInfo = ControllerAndroid.getTouch();
  190. if (touchInfo[1] == CKeyEvent.ACTION_MOVE)
  191. {
  192. InteractionManager.TouchPadPosition = new Vector2(touchInfo[2], touchInfo[3]);
  193. KeyStateController3DOF[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_DOWN;
  194. }
  195. else if (touchInfo[1] == CKeyEvent.ACTION_UP)
  196. {
  197. KeyStateController3DOF[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_UP;
  198. }
  199. bool isNoloLeftConnected = ControllerAndroid.isDeviceConn((int) CDevice.NOLO_TYPE.LEFT);
  200. bool isNoloRightConnected = ControllerAndroid.isDeviceConn((int) CDevice.NOLO_TYPE.RIGHT);
  201. if (isNoloLeftConnected)
  202. {
  203. Array.Copy(KeyStateControllerNOLO_Left, KeyStateControllerNOLO_Left_Pre, MAX_INDEX);
  204. int[] keyActionLeft =
  205. ControllerAndroid.getKeyState((int) InteractionManager.NACTION_HAND_TYPE.HAND_LEFT, 0);
  206. KeyStateControllerNOLO_Left = keyActionLeft;
  207. float[] touchInfoLeft = ControllerAndroid.getTouchEvent((int) CDevice.NOLO_TYPE.LEFT);
  208. if (touchInfoLeft[1] == CKeyEvent.ACTION_MOVE)
  209. {
  210. InteractionManager.TouchPadPosition = new Vector2(touchInfoLeft[2], touchInfoLeft[3]);
  211. KeyStateControllerNOLO_Left[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] =
  212. CKeyEvent.ACTION_DOWN;
  213. }
  214. else if (touchInfoLeft[1] == CKeyEvent.ACTION_UP)
  215. {
  216. KeyStateControllerNOLO_Left[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_UP;
  217. }
  218. }
  219. if (isNoloRightConnected)
  220. {
  221. Array.Copy(KeyStateControllerNOLO_Right, KeyStateControllerNOLO_Right_Pre, MAX_INDEX);
  222. int[] keyActionRight =
  223. ControllerAndroid.getKeyState((int) InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT, 0);
  224. KeyStateControllerNOLO_Right = keyActionRight;
  225. float[] touchInfoRight = ControllerAndroid.getTouchEvent((int) CDevice.NOLO_TYPE.RIGHT);
  226. if (touchInfoRight[1] == CKeyEvent.ACTION_MOVE)
  227. {
  228. InteractionManager.TouchPadPosition = new Vector2(touchInfoRight[2], touchInfoRight[3]);
  229. KeyStateControllerNOLO_Right[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] =
  230. CKeyEvent.ACTION_DOWN;
  231. }
  232. else if (touchInfoRight[1] == CKeyEvent.ACTION_UP)
  233. {
  234. KeyStateControllerNOLO_Right[CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH] = CKeyEvent.ACTION_UP;
  235. }
  236. }
  237. }
  238. // 3Dof/6Dof Controller
  239. if (Application.isEditor && NxrViewer.Instance.RemoteDebug && NxrViewer.Instance.RemoteController)
  240. {
  241. Array.Copy(KeyStateController3DOF, KeyStateController3DOF_Pre, MAX_INDEX);
  242. NibiruEmulatorManager nibiruEmulatorManager = NibiruEmulatorManager.Instance;
  243. Array.Copy(nibiruEmulatorManager.KeyStateController3DOF, KeyStateController3DOF, MAX_INDEX);
  244. }
  245. // 内部事件处理返回键逻辑
  246. if (GetKeyUp(CKeyEvent.KEYCODE_BACK) ||
  247. GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU) ||
  248. GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU, InteractionManager.NACTION_HAND_TYPE.HAND_LEFT) ||
  249. GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU, InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT))
  250. {
  251. bool EatBackKeyEvent = false;
  252. if (NibiruRemindBox.Instance && NibiruRemindBox.Instance.remindbox != null)
  253. {
  254. NibiruRemindBox.Instance.ReleaseDestory();
  255. EatBackKeyEvent = true;
  256. }
  257. if (NibiruShutDownBox.Instance && NibiruShutDownBox.Instance.Showing())
  258. {
  259. NibiruShutDownBox.Instance.ReleaseDestory();
  260. EatBackKeyEvent = true;
  261. }
  262. if (NibiruKeyBoard.Instance.isShown())
  263. {
  264. NibiruKeyBoard.Instance.Dismiss();
  265. EatBackKeyEvent = true;
  266. Debug.Log("NibiruKeyBoard->Dismiss");
  267. }
  268. if (EatBackKeyEvent)
  269. {
  270. Debug.Log("EatBackKeyEvent");
  271. KeyStateHMD[CKeyEvent.KEYCODE_BACK] = CKeyEvent.ACTION_UP;
  272. KeyStateController3DOF[CKeyEvent.KEYCODE_CONTROLLER_MENU] = CKeyEvent.ACTION_UP;
  273. KeyStateControllerNOLO_Left[CKeyEvent.KEYCODE_CONTROLLER_MENU] = CKeyEvent.ACTION_UP;
  274. KeyStateControllerNOLO_Right[CKeyEvent.KEYCODE_CONTROLLER_MENU] = CKeyEvent.ACTION_UP;
  275. KeyStateHMD_Pre[CKeyEvent.KEYCODE_BACK] = CKeyEvent.ACTION_UP;
  276. KeyStateController3DOF_Pre[CKeyEvent.KEYCODE_CONTROLLER_MENU] = CKeyEvent.ACTION_UP;
  277. KeyStateControllerNOLO_Left_Pre[CKeyEvent.KEYCODE_CONTROLLER_MENU] = CKeyEvent.ACTION_UP;
  278. KeyStateControllerNOLO_Right_Pre[CKeyEvent.KEYCODE_CONTROLLER_MENU] = CKeyEvent.ACTION_UP;
  279. }
  280. }
  281. bool IsTouchpadUp = GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD) ||
  282. GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD,
  283. InteractionManager.NACTION_HAND_TYPE.HAND_LEFT) ||
  284. GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD,
  285. InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT);
  286. if (IsTouchpadUp)
  287. {
  288. NxrViewer.Instance.Triggered = true;
  289. }
  290. }
  291. /// <summary>
  292. /// Get the connect status of nolo 6Dof controller
  293. /// </summary>
  294. /// <returns>
  295. /// true connected
  296. /// false disconnected
  297. /// </returns>
  298. public static bool IsNoloControllerConnected()
  299. {
  300. return InteractionManager.IsSixDofController;
  301. }
  302. /// <summary>
  303. /// Get the connect status of 3Dof controller
  304. /// </summary>
  305. /// <returns>
  306. /// true connected
  307. /// false disconnected
  308. /// </returns>
  309. public static bool Is3DofControllerConnected()
  310. {
  311. return InteractionManager.Is3DofControllerConnected();
  312. }
  313. /// <summary>
  314. /// Check hmd key status, whether the button is pressed.
  315. /// </summary>
  316. /// <param name="key">refer to CKeyEvent</param>
  317. /// <returns></returns>
  318. public static bool GetKeyPressed(int key)
  319. {
  320. if (KeyStateHMD[key] == CKeyEvent.ACTION_DOWN)
  321. {
  322. return true;
  323. }
  324. return false;
  325. }
  326. /// <summary>
  327. /// Check hmd key status, whether the button is down.
  328. /// </summary>
  329. /// <param name="key">refer to CKeyEvent</param>
  330. /// <returns></returns>
  331. public static bool GetKeyDown(int key)
  332. {
  333. if (KeyStateHMD[key] == CKeyEvent.ACTION_DOWN && KeyStateHMD_Pre[key] == CKeyEvent.ACTION_UP)
  334. {
  335. return true;
  336. }
  337. return false;
  338. }
  339. /// <summary>
  340. /// Check hmd key status, whether the button is up.
  341. /// </summary>
  342. /// <param name="key">refer to CKeyEvent</param>
  343. /// <returns></returns>
  344. public static bool GetKeyUp(int key)
  345. {
  346. if (KeyStateHMD_Pre[key] == CKeyEvent.ACTION_DOWN && KeyStateHMD[key] == CKeyEvent.ACTION_UP)
  347. {
  348. return true;
  349. }
  350. return false;
  351. }
  352. /// <summary>
  353. /// Check 3dof controller key status, whether the button is down.
  354. /// </summary>
  355. /// <param name="key">refer to CKeyEvent</param>
  356. /// <returns></returns>
  357. public static bool GetControllerKeyDown(int key)
  358. {
  359. Debug.Log("NxrInput-GetControllerKeyDown:"+(KeyStateController3DOF[key] == CKeyEvent.ACTION_DOWN)+","+(KeyStateController3DOF_Pre[key] == CKeyEvent.ACTION_UP));
  360. if (KeyStateController3DOF[key] == CKeyEvent.ACTION_DOWN &&
  361. KeyStateController3DOF_Pre[key] == CKeyEvent.ACTION_UP)
  362. {
  363. return true;
  364. }
  365. return false;
  366. }
  367. /// <summary>
  368. /// Check 3dof controller key status, whether the button is pressed.
  369. /// </summary>
  370. /// <param name="key">refer to CKeyEvent</param>
  371. /// <returns></returns>
  372. public static bool GetControllerKeyPressed(int key)
  373. {
  374. if (KeyStateController3DOF[key] == CKeyEvent.ACTION_DOWN)
  375. {
  376. return true;
  377. }
  378. return false;
  379. }
  380. /// <summary>
  381. /// Check 3dof controller status, whether the button is up.
  382. /// </summary>
  383. /// <param name="key">refer to CKeyEvent</param>
  384. /// <returns></returns>
  385. public static bool GetControllerKeyUp(int key)
  386. {
  387. if (KeyStateController3DOF_Pre[key] == CKeyEvent.ACTION_DOWN &&
  388. KeyStateController3DOF[key] == CKeyEvent.ACTION_UP)
  389. {
  390. return true;
  391. }
  392. return false;
  393. }
  394. /// <summary>
  395. /// Check 6dof controller key status, whether the button is down.
  396. /// </summary>
  397. /// <param name="key">refer to CKeyEvent</param>
  398. /// <param name="handType">left or right</param>
  399. /// <returns></returns>
  400. public static bool GetControllerKeyDown(int key, InteractionManager.NACTION_HAND_TYPE handType)
  401. {
  402. bool isDown = false;
  403. if (handType == InteractionManager.NACTION_HAND_TYPE.HAND_LEFT)
  404. {
  405. isDown = KeyStateControllerNOLO_Left[key] == CKeyEvent.ACTION_DOWN &&
  406. KeyStateControllerNOLO_Left_Pre[key] == CKeyEvent.ACTION_UP;
  407. }
  408. else if (handType == InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT)
  409. {
  410. isDown = KeyStateControllerNOLO_Right[key] == CKeyEvent.ACTION_DOWN &&
  411. KeyStateControllerNOLO_Right_Pre[key] == CKeyEvent.ACTION_UP;
  412. }
  413. if (isDown)
  414. {
  415. return true;
  416. }
  417. return false;
  418. }
  419. /// <summary>
  420. /// Check 6dof controller key status, whether the button is pressed.
  421. /// </summary>
  422. /// <param name="key">refer to CKeyEvent</param>
  423. /// <param name="handType">left or right</param>
  424. /// <returns></returns>
  425. public static bool GetControllerKeyPressed(int key, InteractionManager.NACTION_HAND_TYPE handType)
  426. {
  427. bool isPressed = false;
  428. if (handType == InteractionManager.NACTION_HAND_TYPE.HAND_LEFT)
  429. {
  430. isPressed = KeyStateControllerNOLO_Left[key] == CKeyEvent.ACTION_DOWN;
  431. }
  432. else if (handType == InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT)
  433. {
  434. isPressed = KeyStateControllerNOLO_Right[key] == CKeyEvent.ACTION_DOWN;
  435. }
  436. if (isPressed)
  437. {
  438. return true;
  439. }
  440. return false;
  441. }
  442. /// <summary>
  443. /// Check 6dof controller key status, whether the button is up.
  444. /// </summary>
  445. /// <param name="key">refer to CKeyEvent</param>
  446. /// <param name="handType">left or right</param>
  447. /// <returns></returns>
  448. public static bool GetControllerKeyUp(int key, InteractionManager.NACTION_HAND_TYPE handType)
  449. {
  450. bool isUp = false;
  451. if (handType == InteractionManager.NACTION_HAND_TYPE.HAND_LEFT)
  452. {
  453. isUp = KeyStateControllerNOLO_Left_Pre[key] == CKeyEvent.ACTION_DOWN &&
  454. KeyStateControllerNOLO_Left[key] == CKeyEvent.ACTION_UP;
  455. }
  456. else if (handType == InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT)
  457. {
  458. isUp = KeyStateControllerNOLO_Right_Pre[key] == CKeyEvent.ACTION_DOWN &&
  459. KeyStateControllerNOLO_Right[key] == CKeyEvent.ACTION_UP;
  460. }
  461. if (isUp)
  462. {
  463. return true;
  464. }
  465. return false;
  466. }
  467. /// <summary>
  468. /// Whether the back button is down. (hmd or controller)
  469. /// </summary>
  470. /// <returns></returns>
  471. public static bool OnBackDown()
  472. {
  473. return GetKeyDown(CKeyEvent.KEYCODE_BACK)
  474. || GetControllerKeyDown(CKeyEvent.KEYCODE_CONTROLLER_MENU)
  475. || GetControllerKeyDown(CKeyEvent.KEYCODE_CONTROLLER_MENU,
  476. InteractionManager.NACTION_HAND_TYPE.HAND_LEFT)
  477. || GetControllerKeyDown(CKeyEvent.KEYCODE_CONTROLLER_MENU,
  478. InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT);
  479. }
  480. /// <summary>
  481. /// Whether the back button is up. (hmd or controller)
  482. /// </summary>
  483. /// <returns></returns>
  484. public static bool OnBackUp()
  485. {
  486. return GetKeyUp(CKeyEvent.KEYCODE_BACK)
  487. || GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU)
  488. || GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU,
  489. InteractionManager.NACTION_HAND_TYPE.HAND_LEFT)
  490. || GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU,
  491. InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT);
  492. }
  493. /// <summary>
  494. /// Get Touch Position of Controller Touchpad.
  495. /// Horizontal direction: (Left->Right) -1~1
  496. /// Vertical direction: (Up->Down) -1~1
  497. /// </summary>
  498. public static Vector2 GetTouchPadPosition()
  499. {
  500. return InteractionManager.TouchPadPosition;
  501. }
  502. /// <summary>
  503. /// Get Controller Touchpad Touch Position
  504. /// Horizontal direction: (Left->Right) -1~1
  505. /// Vertical direction: (Up->Down) -1~1
  506. /// </summary>
  507. /// <param name="handType">left or right</param>
  508. /// <returns></returns>
  509. public static Vector2 GetTouchPadPosition(InteractionManager.NACTION_HAND_TYPE handType)
  510. {
  511. return handType == InteractionManager.NACTION_HAND_TYPE.HAND_LEFT
  512. ? InteractionManager.TouchPadPositionLeft
  513. : InteractionManager.TouchPadPositionRight;
  514. }
  515. }
  516. }