InputDeviceKS.cs 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using AOT;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using UnityEngine;
  8. namespace SC.XR.Unity.Module_InputSystem.InputDeviceGC.KS {
  9. public class InputDeviceKS : InputDeviceGC {
  10. public override InputDeviceType inputDeviceType {
  11. get {
  12. return InputDeviceType.KS;
  13. }
  14. }
  15. bool isInvokeOnce = false;
  16. [Header("Enable GameController")]
  17. public bool LeftActive = true;
  18. public bool RightActive = true;
  19. protected override void InputDeviceStart() {
  20. SetActiveInputDevicePart(InputDevicePartType.KSLeft, LeftActive);
  21. SetActiveInputDevicePart(InputDevicePartType.KSRight, RightActive);
  22. }
  23. public override void OnSCLateUpdate() {
  24. base.OnSCLateUpdate();
  25. if(API_GSXR_Slam.SlamManager.plugin != null && API_GSXR_Slam.SlamManager.IsRunning == false)
  26. return;
  27. if(isInvokeOnce == false) {
  28. isInvokeOnce = true;
  29. if(Application.platform == RuntimePlatform.Android) {
  30. try {
  31. API_GSXR_Slam.SlamManager.plugin.GSXR_Set_ControllerKeyEventCallback(KeyEvent);
  32. //API_GSXR_Slam.SlamManager.plugin.GSXR_Set_ControllerKeyTouchEventCallback(KeyTouchEvent);
  33. API_GSXR_Slam.SlamManager.plugin.GSXR_Set_ControllerRockerCallback(JoystickEvent);
  34. API_GSXR_Slam.SlamManager.plugin.GSXR_Set_ControllerHallCallback(HallEvent);
  35. API_GSXR_Slam.SlamManager.plugin.GSXR_Set_ControllerChargingEventCallback(ChargingEvent);
  36. API_GSXR_Slam.SlamManager.plugin.GSXR_Set_ControllerBatteryEventCallback(BatteryEvent);
  37. API_GSXR_Slam.SlamManager.plugin.GSXR_Set_ControllerConnectEventCallback(ConnectEvent);
  38. } catch(Exception e) {
  39. Debug.Log(e);
  40. }
  41. }
  42. }
  43. }
  44. [MonoPInvokeCallback(typeof(Action<int,int, int>))]
  45. public static void KeyEvent(int keycode, int action, int lr) {
  46. Debug.Log("KS -- key event: " + keycode + " " + action + " " + lr);
  47. InputDataGC.GCData.GCKeyList.Add(new GCKeyData() { keycode = keycode, keyevent = action, deivceID = lr });
  48. }
  49. [MonoPInvokeCallback(typeof(Action<bool, bool,bool,bool,int>))]
  50. static void KeyTouchEvent(bool key1, bool key2, bool key3, bool key4, int lr) {
  51. Debug.Log("KS -- KeyTouchEvent:" + key1 + " " + key2 + " " + key3 + " " + key4 + " " + lr);
  52. }
  53. [MonoPInvokeCallback(typeof(Action<int,int, int>))]
  54. static void JoystickEvent(int touch_x, int touch_y, int lr) {
  55. Debug.Log("KS -- JoystickEvent:" + touch_x +" "+ touch_y + " " + lr);
  56. InputDataKS.TempJoystickDataList.Add(new InputDataKS.JoystickData() { JoystickX = touch_x, JoystickY = touch_y, deviceID = lr });
  57. }
  58. [MonoPInvokeCallback(typeof(Action<int,int, int>))]
  59. static void HallEvent(int hall_x, int hall_y, int lr) {
  60. Debug.Log("KS -- HallEvent:" + hall_x + " " + hall_y + " " + lr);
  61. InputDataKS.TempHallDataList.Add(new InputDataKS.HallData() { HallInside = hall_x, HallFoward = hall_y, deviceID = lr });
  62. }
  63. [MonoPInvokeCallback(typeof(Action<bool, int>))]
  64. static void ChargingEvent(bool isCharging, int lr) {
  65. Debug.Log("KS -- ChargingEvent:" + isCharging + " " + lr);
  66. }
  67. [MonoPInvokeCallback(typeof(Action<int, int>))]
  68. static void BatteryEvent(int battery, int lr) {
  69. Debug.Log("KS -- BatteryEvent:" + battery + " " + lr);
  70. }
  71. [MonoPInvokeCallback(typeof(Action<bool,int>))]
  72. static void ConnectEvent(bool isConnected, int lr) {
  73. Debug.Log("KS -- ConnectEvent:" + isConnected + " " + lr);
  74. InputDataKS.StatusDataList.Add(new InputDataKS.StatusData() { isConnected = isConnected, deviceID = lr });
  75. }
  76. }
  77. }