XRInputManager.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. using SC.XR.Unity.Module_InputSystem;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.InputSystem;
  7. using UnityEngine.XR;
  8. using UnityEngine.XR.OpenXR.Input;
  9. public class XRInputManager : MonoBehaviour
  10. {
  11. public InputActionProperty inputEvent;
  12. public List<InputActionReference> listinput;
  13. int xy = 8;
  14. private void Awake()
  15. {
  16. }
  17. // Start is called before the first frame update
  18. void Start()
  19. {
  20. Invoke("startXR", 1f);
  21. /*
  22. return;
  23. for (int i = 0; i < 15; i++)
  24. {
  25. listinput[i].action.Enable();
  26. listinput[i].action.performed += OnEventL;
  27. listinput[i].action.canceled += OnCanceledEventL;
  28. }
  29. for (int i = 15; i < listinput.Count; i++)
  30. {
  31. listinput[i].action.Enable();
  32. listinput[i].action.performed += OnEventR;
  33. listinput[i].action.canceled += OnCanceledEventR;
  34. }
  35. InputDevices.deviceConnected += onDeviceConnected;
  36. InputDevices.deviceDisconnected += onDeviceDisConnected;
  37. Invoke("startXR", 1f);*/
  38. }
  39. private void downTP()
  40. {
  41. }
  42. public GameObject handinput;
  43. public GameObject cinput;
  44. List<Vector3> leftInfo = new List<Vector3>();
  45. List<Vector3> rightInfo = new List<Vector3>();
  46. void startXR()
  47. {
  48. Module_InputSystem.instance.SetActiveInputDevice(InputDeviceType.KS, false);
  49. Module_InputSystem.instance.SetActiveInputDevice(InputDeviceType.Head, true);
  50. Module_InputSystem.instance.SetActiveInputDevice(InputDeviceType.GGT26Dof, false);
  51. }
  52. private void Update()
  53. {
  54. if (Input.GetKeyDown(KeyCode.X))
  55. {
  56. API_GSXR_Module_InputSystem_GGT26Dof.GSXR_GGTRight.inputDataGGT26Dof.inputKeys.InputDataAddKey(InputKeyCode.Enter, InputKeyState.DOWN);
  57. //API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.X, InputKeyState.DOWN);
  58. }
  59. if (Input.GetKeyUp(KeyCode.X))
  60. {
  61. API_GSXR_Module_InputSystem_GGT26Dof.GSXR_GGTRight.inputDataGGT26Dof.inputKeys.InputDataAddKey(InputKeyCode.Enter, InputKeyState.UP);
  62. // API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.X, InputKeyState.UP);
  63. }
  64. }
  65. private void onDeviceDisConnected(UnityEngine.XR.InputDevice obj)
  66. {
  67. if (obj.characteristics.ToString().Contains(InputDeviceCharacteristics.Left.ToString()))
  68. {
  69. Debug.Log("Left===>" + obj.isValid);
  70. }
  71. if (obj.characteristics.ToString().Contains(InputDeviceCharacteristics.Right.ToString()))
  72. {
  73. Debug.Log("Right===>" + obj.isValid);
  74. }
  75. }
  76. private void OnApplicationPause(bool pause)
  77. {
  78. if (!pause)
  79. {
  80. List<UnityEngine.XR.InputDevice> inputDevices = new List<UnityEngine.XR.InputDevice>();
  81. InputDevices.GetDevices(inputDevices);
  82. for (int i = 0; i < inputDevices.Count; i++)
  83. {
  84. onDeviceConnected(inputDevices[i]);
  85. }
  86. }
  87. }
  88. private void onDeviceConnected(UnityEngine.XR.InputDevice obj)
  89. {
  90. if (obj.characteristics.ToString().Contains(InputDeviceCharacteristics.Left.ToString()))
  91. {
  92. Debug.Log("Left===>" + obj.isValid);
  93. }
  94. if (obj.characteristics.ToString().Contains(InputDeviceCharacteristics.Right.ToString()))
  95. {
  96. Debug.Log("Right===>" + obj.isValid);
  97. }
  98. }
  99. private void OnCanceledEventL(InputAction.CallbackContext context)
  100. {
  101. Debug.Log("OnCanceledEventL" + context.control.name);
  102. switch (context.control.name)
  103. {
  104. case "secondarytouched":
  105. break;
  106. case "secondarybutton":
  107. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.Y, InputKeyState.UP);
  108. break;
  109. case "primarytouched":
  110. break;
  111. case "primarybutton":
  112. Debug.Log("InputKeyCode.A===¡·UP");
  113. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.X, InputKeyState.UP);
  114. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.Enter, InputKeyState.UP);
  115. break;
  116. case "touchpadtouched":
  117. break;
  118. case "thumbstickclicked":
  119. break;
  120. case "thumbstick":
  121. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.JoystickX = xy + (int)(context.ReadValue<Vector2>().x * 10);
  122. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.JoystickY = xy + (int)(context.ReadValue<Vector2>().y * 10);
  123. break;
  124. case "grip":
  125. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.HallInside = 10 - (int)((context.ReadValue<float>()) * 10f);
  126. break;
  127. case "grippressed":
  128. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.LHallInside, InputKeyState.UP);
  129. break;
  130. case "trigger":
  131. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.HallFoward = 10 - (int)((context.ReadValue<float>()) * 10f);
  132. break;
  133. case "menu":
  134. Module_InputSystem.instance.SetActiveInputDevice(InputDeviceType.KS, true);
  135. Module_InputSystem.instance.SetActiveInputDevice(InputDeviceType.Head, false);
  136. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.LFunction, InputKeyState.UP);
  137. break;
  138. }
  139. }
  140. void OnEventL(InputAction.CallbackContext context)
  141. {
  142. Debug.Log("OnEventL" + context.control.name);
  143. switch (context.control.name)
  144. {
  145. case "secondarytouched":
  146. break;
  147. case "secondarybutton":
  148. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.Y, InputKeyState.DOWN);
  149. break;
  150. case "primarytouched":
  151. break;
  152. case "primarybutton":
  153. Debug.Log("InputKeyCode.A===¡·DOWN");
  154. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.X, InputKeyState.DOWN);
  155. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.Enter, InputKeyState.DOWN);
  156. break;
  157. case "touchpadtouched":
  158. break;
  159. case "thumbstickclicked":
  160. break;
  161. case "thumbstick":
  162. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.JoystickX = xy + (int)(context.ReadValue<Vector2>().x * 10);
  163. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.JoystickY = xy + (int)(context.ReadValue<Vector2>().y * 10);
  164. break;
  165. case "grip":
  166. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.HallInside = 10 - (int)((context.ReadValue<float>()) * 10f);
  167. break;
  168. case "grippressed":
  169. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.LHallInside, InputKeyState.DOWN);
  170. break;
  171. case "trigger":
  172. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.HallFoward = 10 - (int)((context.ReadValue<float>()) * 10f);
  173. break;
  174. case "menu":
  175. API_GSXR_Module_InputSystem_KS.GSXR_KSLeft.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.LFunction, InputKeyState.DOWN);
  176. break;
  177. }
  178. }
  179. private void OnCanceledEventR(InputAction.CallbackContext context)
  180. {
  181. Debug.Log("OnCanceledEventR" + context.control.name);
  182. switch (context.control.name)
  183. {
  184. case "secondarytouched":
  185. break;
  186. case "secondarybutton":
  187. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.B, InputKeyState.UP);
  188. break;
  189. case "primarytouched":
  190. break;
  191. case "primarybutton":
  192. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.A, InputKeyState.UP);
  193. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.Enter, InputKeyState.UP);
  194. break;
  195. case "touchpadtouched":
  196. break;
  197. case "thumbstickclicked":
  198. break;
  199. case "thumbstick":
  200. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.JoystickX = xy + (int)(context.ReadValue<Vector2>().x * 10);
  201. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.JoystickY = xy + (int)(context.ReadValue<Vector2>().y * 10);
  202. break;
  203. case "grip":
  204. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.HallInside = 10 - (int)((context.ReadValue<float>()) * 10f);
  205. break;
  206. case "grippressed":
  207. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.RHallInside, InputKeyState.UP);
  208. break;
  209. case "trigger":
  210. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.HallFoward = 10 - (int)((context.ReadValue<float>()) * 10f);
  211. break;
  212. case "menu":
  213. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.RFunction, InputKeyState.UP);
  214. break;
  215. }
  216. }
  217. void OnEventR(InputAction.CallbackContext context)
  218. {
  219. Debug.Log("OnEventR" + context.control.name);
  220. switch (context.control.name)
  221. {
  222. case "secondarytouched":
  223. break;
  224. case "secondarybutton":
  225. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.B, InputKeyState.DOWN);
  226. break;
  227. case "primarytouched":
  228. break;
  229. case "primarybutton":
  230. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.A, InputKeyState.DOWN);
  231. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.Enter, InputKeyState.DOWN);
  232. break;
  233. case "touchpadtouched":
  234. break;
  235. case "thumbstickclicked":
  236. break;
  237. case "thumbstick":
  238. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.JoystickX = xy + (int)(context.ReadValue<Vector2>().x * 10);
  239. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.JoystickY = xy + (int)(context.ReadValue<Vector2>().y * 10);
  240. break;
  241. case "grip":
  242. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.HallInside = 10 - (int)((context.ReadValue<float>()) * 10f);
  243. break;
  244. case "grippressed":
  245. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.RHallInside, InputKeyState.DOWN);
  246. break;
  247. case "trigger":
  248. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.HallFoward = 10 - (int)((context.ReadValue<float>()) * 10f);
  249. break;
  250. case "menu":
  251. Module_InputSystem.instance.SetActiveInputDevice(InputDeviceType.KS, true);
  252. Module_InputSystem.instance.SetActiveInputDevice(InputDeviceType.Head, false);
  253. API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDataKS.inputKeys.InputDataAddKey(InputKeyCode.RFunction, InputKeyState.DOWN);
  254. break;
  255. }
  256. }
  257. // Debug.Log("OnEvent=name==>" + context.control.name);
  258. /*
  259. Debug.Log("OnEvent=layout==>" + context.control.layout);
  260. Debug.Log("OnEvent=noisy==>" + context.control.noisy);
  261. Debug.Log("OnEvent=path==>" + context.control.path);
  262. Debug.Log("OnEvent=shortDisplayName==>" + context.control.shortDisplayName);
  263. Debug.Log("OnEvent=synthetic==>" + context.control.synthetic);
  264. Debug.Log("OnEvent=valueSizeInBytes==>" + context.control.valueSizeInBytes);
  265. Debug.Log("OnEvent=valueType==>" + context.control.valueType.Name);
  266. Debug.Log("OnEvent=variants==>" + context.control.variants);
  267. Debug.Log("OnEvent=variants==>" + context.control.EvaluateMagnitude());*/
  268. }