InputTest.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. using UnityEngine;
  2. using Nxr.Internal;
  3. using NibiruTask;
  4. namespace NXR.Samples
  5. {
  6. public class InputTest : MonoBehaviour
  7. {
  8. public TextMesh textMesh;
  9. public TextMesh textMeshControllerLeft;
  10. public TextMesh textMeshControllerRight;
  11. InteractionManager.NACTION_HAND_TYPE[] handTypes = new InteractionManager.NACTION_HAND_TYPE[]
  12. {
  13. InteractionManager.NACTION_HAND_TYPE.HAND_LEFT,
  14. InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT
  15. };
  16. int[] threeDofCtrlKeyCode = new int[] {
  17. CKeyEvent.KEYCODE_CONTROLLER_TRIGGER,
  18. CKeyEvent.KEYCODE_CONTROLLER_MENU,
  19. CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD,
  20. CKeyEvent.KEYCODE_CONTROLLER_VOLUMN_DOWN,
  21. CKeyEvent.KEYCODE_CONTROLLER_VOLUMN_UP,
  22. CKeyEvent.KEYCODE_BUTTON_A,
  23. CKeyEvent.KEYCODE_BUTTON_B,
  24. CKeyEvent.KEYCODE_BUTTON_X,
  25. CKeyEvent.KEYCODE_BUTTON_Y
  26. };
  27. string[] threeDofCtrlKeyStr = new string[] {
  28. "3Dof Controller Trigger : ",
  29. "3Dof Controller Menu : ",
  30. "3Dof Controller Touchpad : ",
  31. "3Dof Controller VolumnDown : ",
  32. "3Dof Controller VolumnUp : ",
  33. "3Dof Controller A : ",
  34. "3Dof Controller B : ",
  35. "3Dof Controller X : ",
  36. "3Dof Controller Y : "
  37. };
  38. int[] sixDofCtrlKeyCode = new int[] {
  39. CKeyEvent.KEYCODE_CONTROLLER_TRIGGER,
  40. CKeyEvent.KEYCODE_CONTROLLER_MENU,
  41. CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD,
  42. CKeyEvent.KEYCODE_CONTROLLER_GRIP,
  43. CKeyEvent.KEYCODE_BUTTON_A,
  44. CKeyEvent.KEYCODE_BUTTON_B,
  45. CKeyEvent.KEYCODE_BUTTON_X,
  46. CKeyEvent.KEYCODE_BUTTON_Y
  47. };
  48. string[] sixDofCtrlKeyStr = new string[] {
  49. "SixDof Controller Trigger : ",
  50. "SixDof Controller Menu : ",
  51. "SixDof Controller Touchpad : ",
  52. "SixDof Controller Grip : ",
  53. "SixDof Controller A : ",
  54. "SixDof Controller B : ",
  55. "SixDof Controller X : ",
  56. "SixDof Controller Y : ",
  57. };
  58. // Start is called before the first frame update
  59. void Start()
  60. {
  61. }
  62. // Update is called once per frame
  63. void Update()
  64. {
  65. //GameObject controllerDot = NibiruAxis.NxrPlayerCtrl.Instance.GetControllerLaserDot();
  66. //if (controllerDot != null)
  67. //{
  68. // Debug.Log("Contoller Dot:" + controllerDot.transform.position.ToString());
  69. //}
  70. //NxrReticle reticle = NxrViewer.Instance.GetNxrReticle();
  71. //if (reticle.IsShowing())
  72. //{
  73. // Debug.Log("Reticle:" + reticle.GetReticlePointer().transform.position.ToString());
  74. //}
  75. if (NxrInput.GetKeyDown(CKeyEvent.KEYCODE_DPAD_CENTER))
  76. {
  77. textMesh.text = "HMD Enter : Down";
  78. }
  79. if (NxrInput.GetKeyPressed(CKeyEvent.KEYCODE_DPAD_CENTER))
  80. {
  81. textMesh.text = "HMD Enter : Pressed";
  82. }
  83. if (NxrInput.GetKeyUp(CKeyEvent.KEYCODE_DPAD_CENTER))
  84. {
  85. textMesh.text = "HMD Enter : Up";
  86. }
  87. if (NxrInput.GetKeyDown(CKeyEvent.KEYCODE_BACK))
  88. {
  89. textMesh.text = "HMD Back : Down";
  90. }
  91. if (NxrInput.GetKeyPressed(CKeyEvent.KEYCODE_BACK))
  92. {
  93. textMesh.text = "HMD Back : Pressed";
  94. }
  95. if (NxrInput.GetKeyUp(CKeyEvent.KEYCODE_BACK))
  96. {
  97. textMesh.text = "HMD Back : Up";
  98. }
  99. if (NxrInput.GetKeyDown(CKeyEvent.KEYCODE_DPAD_LEFT))
  100. {
  101. textMesh.text = "HMD Left : Down";
  102. }
  103. if (NxrInput.GetKeyPressed(CKeyEvent.KEYCODE_DPAD_LEFT))
  104. {
  105. textMesh.text = "HMD Left : Pressed";
  106. }
  107. if (NxrInput.GetKeyUp(CKeyEvent.KEYCODE_DPAD_LEFT))
  108. {
  109. textMesh.text = "HMD Left : Up";
  110. }
  111. if (NxrInput.GetKeyDown(CKeyEvent.KEYCODE_DPAD_RIGHT))
  112. {
  113. textMesh.text = "HMD Right : Down";
  114. }
  115. if (NxrInput.GetKeyPressed(CKeyEvent.KEYCODE_DPAD_RIGHT))
  116. {
  117. textMesh.text = "HMD Right : Pressed";
  118. }
  119. if (NxrInput.GetKeyUp(CKeyEvent.KEYCODE_DPAD_RIGHT))
  120. {
  121. textMesh.text = "HMD Right : Up";
  122. }
  123. if (NxrInput.GetKeyDown(CKeyEvent.KEYCODE_DPAD_UP))
  124. {
  125. textMesh.text = "HMD Up : Down";
  126. }
  127. if (NxrInput.GetKeyPressed(CKeyEvent.KEYCODE_DPAD_UP))
  128. {
  129. textMesh.text = "HMD Up : Pressed";
  130. }
  131. if (NxrInput.GetKeyUp(CKeyEvent.KEYCODE_DPAD_UP))
  132. {
  133. textMesh.text = "HMD Up : Up";
  134. }
  135. if (NxrInput.GetKeyDown(CKeyEvent.KEYCODE_DPAD_DOWN))
  136. {
  137. textMesh.text = "HMD Down : Down";
  138. }
  139. if (NxrInput.GetKeyPressed(CKeyEvent.KEYCODE_DPAD_DOWN))
  140. {
  141. textMesh.text = "HMD Down : Pressed";
  142. }
  143. if (NxrInput.GetKeyUp(CKeyEvent.KEYCODE_DPAD_DOWN))
  144. {
  145. textMesh.text = "HMD Down : Up";
  146. }
  147. // 3DOF Controller
  148. if(InteractionManager.Is3DofControllerConnected())
  149. {
  150. InteractionManager.NACTION_HAND_TYPE mHandType = InteractionManager.GetHandTypeByHandMode();
  151. TextMesh textMeshController = textMeshControllerRight;
  152. if (mHandType == InteractionManager.NACTION_HAND_TYPE.HAND_LEFT)
  153. {
  154. textMeshController = textMeshControllerLeft;
  155. }
  156. bool HasKeyDown = false;
  157. for (int i = 0, size = threeDofCtrlKeyCode.Length; i < size; i++)
  158. {
  159. int keyCode = threeDofCtrlKeyCode[i];
  160. string keyStr = threeDofCtrlKeyStr[i];
  161. if (NxrInput.GetControllerKeyDown(keyCode))
  162. {
  163. textMeshController.text = keyStr + "Down_" + mHandType.ToString();
  164. HasKeyDown = true;
  165. }
  166. if (!HasKeyDown && NxrInput.GetControllerKeyPressed(keyCode))
  167. {
  168. textMeshController.text = keyStr + "Pressed_" + mHandType.ToString();
  169. HasKeyDown = true;
  170. }
  171. if (!HasKeyDown)
  172. {
  173. if (NxrInput.GetControllerKeyUp(keyCode))
  174. {
  175. textMeshController.text = keyStr + "Up_" + mHandType.ToString();
  176. }
  177. }
  178. }
  179. }
  180. else
  181. {
  182. // SixDof Controller
  183. foreach (InteractionManager.NACTION_HAND_TYPE HandType in handTypes)
  184. {
  185. TextMesh textMeshCtrl = null;
  186. if (HandType == InteractionManager.NACTION_HAND_TYPE.HAND_LEFT)
  187. {
  188. textMeshCtrl = textMeshControllerLeft;
  189. }
  190. else
  191. {
  192. textMeshCtrl = textMeshControllerRight;
  193. }
  194. bool HasKeyDown = false;
  195. for (int i = 0, size = sixDofCtrlKeyCode.Length; i < size; i++)
  196. {
  197. int keyCode = sixDofCtrlKeyCode[i];
  198. string keyStr = sixDofCtrlKeyStr[i];
  199. if (NxrInput.GetControllerKeyDown(keyCode, HandType))
  200. {
  201. textMeshCtrl.text = keyStr + "Down_" + HandType.ToString();
  202. HasKeyDown = true;
  203. }
  204. if (!HasKeyDown && NxrInput.GetControllerKeyPressed(keyCode, HandType))
  205. {
  206. textMeshCtrl.text = keyStr + "Pressed_" + HandType.ToString();
  207. HasKeyDown = true;
  208. }
  209. if (!HasKeyDown)
  210. {
  211. if (NxrInput.GetControllerKeyUp(keyCode, HandType))
  212. {
  213. textMeshCtrl.text = keyStr + "Up_" + HandType.ToString();
  214. }
  215. }
  216. }
  217. }
  218. }
  219. }
  220. }
  221. }