InputDeviceKS.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using AOT;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using UnityEngine;
  9. namespace SC.XR.Unity.Module_InputSystem.InputDeviceGC.KS {
  10. public class InputDeviceKS : InputDeviceGC {
  11. public override InputDeviceType inputDeviceType {
  12. get {
  13. return InputDeviceType.KS;
  14. }
  15. }
  16. private Coroutine callback=null;
  17. public static bool isShowLog = false;
  18. [Header("Enable GameController")]
  19. public bool LeftActive = true;
  20. public bool RightActive = true;
  21. protected override void InputDeviceStart() {
  22. int num = API_GSXR_Slam.plugin.GSXR_Get_ControllerNum();
  23. DebugMy.Log("GSXR_Get_ControllerNum:"+num,this,true);
  24. if (num == 2) {
  25. SetActiveInputDevicePart(InputDevicePartType.KSLeft, LeftActive);
  26. SetActiveInputDevicePart(InputDevicePartType.KSRight, RightActive);
  27. } else if (num == 1) {
  28. SetActiveInputDevicePart(InputDevicePartType.KSRight, RightActive);
  29. }
  30. //if (callback == null) {
  31. // callback = StartCoroutine(StartSetCallBack());
  32. //}
  33. if (API_Module_SDKConfiguration.HasKey("Module_InputSystem", "KS_ShowLog")) {
  34. isShowLog = API_Module_SDKConfiguration.GetBool("Module_InputSystem", "KS_ShowLog", 0);
  35. }
  36. DebugMy.Log("isShowLog:" + isShowLog, this, true);
  37. }
  38. public override void OnSCDisable() {
  39. base.OnSCDisable();
  40. //if (callback != null) { StopCoroutine(StartSetCallBack()); callback = null; }
  41. //SetCallBack(true);
  42. }
  43. IEnumerator StartSetCallBack() {
  44. yield return null;
  45. // yield return new WaitUntil(() => (API_GSXR_Slam.plugin != null && API_GSXR_Slam.SlamManager.IsRunning == true));
  46. SetCallBack();
  47. callback = null;
  48. }
  49. void SetCallBack(bool isSetNull = false) {
  50. if (API_GSXR_Slam.plugin == null)
  51. return;
  52. if (isSetNull == false) {
  53. DebugMy.Log("Controller SetCallBack", this, true);
  54. try {
  55. API_GSXR_Slam.plugin.GSXR_Set_ControllerKeyEventCallback(KeyEvent);
  56. API_GSXR_Slam.plugin.GSXR_Set_ControllerKeyTouchEventCallback(KeyTouchEvent);
  57. API_GSXR_Slam.plugin.GSXR_Set_ControllerRockerCallback(JoystickEvent);
  58. API_GSXR_Slam.plugin.GSXR_Set_ControllerHallCallback(HallEvent);
  59. API_GSXR_Slam.plugin.GSXR_Set_ControllerChargingEventCallback(ChargingEvent);
  60. API_GSXR_Slam.plugin.GSXR_Set_ControllerBatteryEventCallback(BatteryEvent);
  61. API_GSXR_Slam.plugin.GSXR_Set_ControllerConnectEventCallback(ConnectEvent);
  62. API_GSXR_Slam.plugin.GSXR_Set_ControllerTouchPanelCallback(OnTouchPanelEvent);
  63. } catch (Exception e) {
  64. Debug.Log(e);
  65. }
  66. } else {
  67. DebugMy.Log("Controller SetCallBack Null", this, true);
  68. try {
  69. API_GSXR_Slam.plugin.GSXR_Set_ControllerKeyEventCallback(null);
  70. API_GSXR_Slam.plugin.GSXR_Set_ControllerKeyTouchEventCallback(null);
  71. API_GSXR_Slam.plugin.GSXR_Set_ControllerRockerCallback(null);
  72. API_GSXR_Slam.plugin.GSXR_Set_ControllerHallCallback(null);
  73. API_GSXR_Slam.plugin.GSXR_Set_ControllerChargingEventCallback(null);
  74. API_GSXR_Slam.plugin.GSXR_Set_ControllerBatteryEventCallback(null);
  75. API_GSXR_Slam.plugin.GSXR_Set_ControllerConnectEventCallback(null);
  76. API_GSXR_Slam.plugin.GSXR_Set_ControllerTouchPanelCallback(null);
  77. } catch (Exception e) {
  78. Debug.Log(e);
  79. }
  80. }
  81. }
  82. [MonoPInvokeCallback(typeof(Action<int,int, int>))]
  83. public static void KeyEvent(int keycode, int action, int lr) {
  84. if (isShowLog) {
  85. Debug.Log("KS -- Keyevent: " + keycode + " " + action + " " + lr);
  86. }
  87. InputDataGC.GCData.GCKeyList.Add(new GCKeyData() { keycode = keycode, keyevent = action, deivceID = lr });
  88. }
  89. [MonoPInvokeCallback(typeof(Action<int,bool,int>))]
  90. static void KeyTouchEvent(int keycode, bool touch, int lr) {
  91. if (isShowLog) {
  92. Debug.Log("KS -- KeyTouchEvent:" + keycode + " " + touch + " " + lr);
  93. }
  94. if (touch) {
  95. InputDataGC.GCData.GCKeyList.Add(new GCKeyData() { keycode = keycode, keyevent = (int)(KSKeyState.TouchEnter), deivceID = lr });
  96. } else {
  97. InputDataGC.GCData.GCKeyList.Add(new GCKeyData() { keycode = keycode, keyevent = (int)(KSKeyState.TouchExit), deivceID = lr });
  98. }
  99. //InputDataKS.KeyTouchDataList.Add(new InputDataKS.KeyTouchData() { keycode = keycode, touch = touch, deviceID = lr });
  100. }
  101. [MonoPInvokeCallback(typeof(Action<int,int, int>))]
  102. static void JoystickEvent(int touch_x, int touch_y, int lr) {
  103. if (isShowLog) {
  104. Debug.Log("KS -- JoystickEvent:" + touch_x + " " + touch_y + " " + lr);
  105. }
  106. InputDataKS.TempJoystickDataList.Add(new InputDataKS.JoystickData() { JoystickX = touch_x, JoystickY = touch_y, deviceID = lr });
  107. }
  108. [MonoPInvokeCallback(typeof(Action<int,int, int>))]
  109. static void HallEvent(int hall_x, int hall_y, int lr) {
  110. if (isShowLog) {
  111. Debug.Log("KS -- HallEvent:" + hall_x + " " + hall_y + " " + lr);
  112. }
  113. InputDataKS.TempHallDataList.Add(new InputDataKS.HallData() { HallInside = hall_x, HallFoward = hall_y, deviceID = lr });
  114. }
  115. [MonoPInvokeCallback(typeof(Action<bool, int>))]
  116. static void ChargingEvent(bool isCharging, int lr) {
  117. if (isShowLog) {
  118. Debug.Log("KS -- ChargingEvent:" + isCharging + " " + lr);
  119. }
  120. InputDataKS.ChargingEventDataList.Add(new InputDataKS.ChargingEventData() { isCharging = isCharging, deviceID = lr });
  121. }
  122. [MonoPInvokeCallback(typeof(Action<int, int>))]
  123. static void BatteryEvent(int battery, int lr) {
  124. if (isShowLog) {
  125. Debug.Log("KS -- BatteryEvent:" + battery + " " + lr);
  126. }
  127. InputDataKS.BatteryPowerEventDataList.Add(new InputDataKS.BatteryPowerData() { BatteryPower = battery, deviceID = lr });
  128. }
  129. [MonoPInvokeCallback(typeof(Action<bool,int>))]
  130. static void ConnectEvent(bool isConnected, int lr) {
  131. Debug.Log("KS -- ConnectEvent:" + isConnected + " " + lr);
  132. InputDataKS.StatusDataList.Add(new InputDataKS.StatusData() { isConnected = isConnected, deviceID = lr });
  133. }
  134. [MonoPInvokeCallback(typeof(Action<float, float, int, int>))]
  135. static void OnTouchPanelEvent(float x, float y, int touch, int lr) {
  136. if (isShowLog) {
  137. Debug.Log("KS -- OnTouchPanelEvent:" + x + " " + y + " " + touch + " " + lr);
  138. }
  139. InputDataKS.TouchPanelDataList.Add(new InputDataKS.TouchPanelData() { x = x, y = y, deviceID = lr });
  140. }
  141. public override void OnSCUpdate() {
  142. Fps.tempControllerLogic1Time = Time.realtimeSinceStartup;
  143. base.OnSCUpdate();
  144. Fps.ControllerLogic1Time = Mathf.Lerp(Fps.ControllerLogic1Time, 1000 * (Time.realtimeSinceStartup - Fps.tempControllerLogic1Time), Fps.lerp);
  145. }
  146. public override void OnSCLateUpdate() {
  147. Fps.tempControllerLogic2Time = Time.realtimeSinceStartup;
  148. base.OnSCLateUpdate();
  149. Fps.ControllerLogic2Time = Mathf.Lerp(Fps.ControllerLogic2Time, 1000 * (Time.realtimeSinceStartup - Fps.tempControllerLogic2Time), Fps.lerp);
  150. }
  151. }
  152. }