InputDeviceKS.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. public override void OnSCLateUpdate() {
  17. base.OnSCLateUpdate();
  18. if(SvrPlugin.Instance != null && SvrManager.Instance.IsRunning == false)
  19. return;
  20. if(isInvokeOnce == false) {
  21. isInvokeOnce = true;
  22. if(Application.platform == RuntimePlatform.Android) {
  23. try {
  24. SvrPlugin.Instance.HandShank_SetKeyEventCallback(KeyEvent);
  25. SvrPlugin.Instance.HandShank_SetKeyTouchEventCallback(KeyTouchEvent);
  26. SvrPlugin.Instance.HandShank_SetTouchEventCallback(JoystickEvent);
  27. SvrPlugin.Instance.HandShank_SetHallEventCallback(HallEvent);
  28. SvrPlugin.Instance.HandShank_SetChargingEventCallback(ChargingEvent);
  29. SvrPlugin.Instance.HandShank_SetBatteryEventCallback(BatteryEvent);
  30. SvrPlugin.Instance.HandShank_SetConnectEventCallback(ConnectEvent);
  31. } catch(Exception e) {
  32. Debug.Log(e);
  33. }
  34. }
  35. }
  36. }
  37. [MonoPInvokeCallback(typeof(SvrPlugin.OnKeyEvent))]
  38. public static void KeyEvent(int keycode, int action, int lr) {
  39. Debug.Log("KS -- key event: " + keycode + " " + action + " " + lr);
  40. InputDataGC.GCData.GCKeyList.Add(new GCKeyData() { keycode = keycode, keyevent = action, deivceID = lr });
  41. }
  42. [MonoPInvokeCallback(typeof(SvrPlugin.OnKeyTouchEvent))]
  43. static void KeyTouchEvent(bool key1, bool key2, bool key3, bool key4, int lr) {
  44. Debug.Log("KS -- KeyTouchEvent:" + key1 + " " + key2 + " " + key3 + " " + key4 + " " + lr);
  45. }
  46. [MonoPInvokeCallback(typeof(SvrPlugin.OnTouchEvent))]
  47. static void JoystickEvent(int touch_x, int touch_y, int lr) {
  48. Debug.Log("KS -- JoystickEvent:" + touch_x +" "+ touch_y + " " + lr);
  49. InputDataKS.TempJoystickDataList.Add(new InputDataKS.JoystickData() { JoystickX = touch_x, JoystickY = touch_y, deviceID = lr });
  50. }
  51. [MonoPInvokeCallback(typeof(SvrPlugin.OnHallEvent))]
  52. static void HallEvent(int hall_x, int hall_y, int lr) {
  53. Debug.Log("KS -- HallEvent:" + hall_x + " " + hall_y + " " + lr);
  54. InputDataKS.TempHallDataList.Add(new InputDataKS.HallData() { HallInside = hall_x, HallFoward = hall_y, deviceID = lr });
  55. }
  56. [MonoPInvokeCallback(typeof(SvrPlugin.OnChargingEvent))]
  57. static void ChargingEvent(bool isCharging, int lr) {
  58. Debug.Log("KS -- ChargingEvent:" + isCharging + " " + lr);
  59. }
  60. [MonoPInvokeCallback(typeof(SvrPlugin.OnBatteryEvent))]
  61. static void BatteryEvent(int battery, int lr) {
  62. Debug.Log("KS -- BatteryEvent:" + battery + " " + lr);
  63. }
  64. [MonoPInvokeCallback(typeof(SvrPlugin.OnConnectEvent))]
  65. static void ConnectEvent(bool isConnected, int lr) {
  66. Debug.Log("KS -- ConnectEvent:" + isConnected + " " + lr);
  67. InputDataKS.StatusDataList.Add(new InputDataGC.StatusData() { isConnected = isConnected, deviceID = lr });
  68. }
  69. }
  70. }