using AOT; using SC.XR.Unity; using SC.XR.Unity.Module_InputSystem; using SC.XR.Unity.Module_InputSystem.InputDeviceGC.KS; using System; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; using static API_GSXR_Module_InputSystem_KS; using static API_GSXR_Slam; public class ControllerInfoBase : MonoBehaviour { #region CanvasText [SerializeField] protected Text title; [SerializeField] protected TextMeshProUGUI Version; [SerializeField] protected TextMeshProUGUI button_XA; [SerializeField] protected TextMeshProUGUI button_XA2; [SerializeField] protected TextMeshProUGUI button_YB; [SerializeField] protected TextMeshProUGUI button_YB2; [SerializeField] protected TextMeshProUGUI button_Function; [SerializeField] protected TextMeshProUGUI button_Function2; [SerializeField] protected TextMeshProUGUI button_Side; [SerializeField] protected TextMeshProUGUI button_Side2; [SerializeField] protected TextMeshProUGUI button_Trigger; [SerializeField] protected TextMeshProUGUI button_Trigger2; [SerializeField] protected TextMeshProUGUI button_JoystickKey; [SerializeField] protected TextMeshProUGUI button_JoystickKey2; [SerializeField] protected TextMeshProUGUI joyStick; [SerializeField] protected TextMeshProUGUI Hall_Forward; [SerializeField] protected TextMeshProUGUI Hall_Inside; [SerializeField] protected TextMeshProUGUI rotation; [SerializeField] protected TextMeshProUGUI location; [SerializeField] protected TextMeshProUGUI BatteryLevel; [SerializeField] protected TextMeshProUGUI Text_button_XA; [SerializeField] protected TextMeshProUGUI Text_button_YB; [SerializeField] protected TextMeshProUGUI Text_button_Function; [SerializeField] protected TextMeshProUGUI Text_button_Side; [SerializeField] protected TextMeshProUGUI Text_button_Trigger; [SerializeField] protected TextMeshProUGUI Text_button_joystickKey; [SerializeField] protected TextMeshProUGUI Text_rotation; [SerializeField] protected TextMeshProUGUI Text_location; [SerializeField] protected Button vibration; #endregion public bool is_Left = false; bool isOne=true; protected void Start() { API_GSXR_Module_InputSystem.GSXR_KeyDownDelegateRegister(ChangeColor); API_GSXR_Module_InputSystem.GSXR_KeyDownDelegateRegister(KeyDown); API_GSXR_Module_InputSystem.GSXR_KeyUpDelegateRegister(KeyUp); API_GSXR_Module_InputSystem.GSXR_KeyLongDelegateRegister(KeyLong); API_GSXR_Module_InputSystem.GSXR_KeyTouchEnterDelegateRegister(KeyTouchEnter); API_GSXR_Module_InputSystem.GSXR_KeyTouchExitDelegateRegister(KeyTouchExit); API_GSXR_Slam.plugin.GSXR_Set_ControllerHallRangeCallback(OnHallRangeEvent); } protected void Update() { //if (API_GSXR_Slam.SlamManager == null && !API_GSXR_Slam.SlamManager.IsRunning) //{ // return; //} if (isOne) { isOne = false; SetControllerType(); } ShowControllerData(); } protected void LateUpdate() { //if (API_GSXR_Slam.SlamManager == null && !API_GSXR_Slam.SlamManager.IsRunning) //{ // return; //} UpdateHallRange(); ShowDeviceBattery(); } protected void SetControllerType() { if (is_Left) { title.text = "Left Controller"; Version.text = "Version:" + API_GSXR_Slam.plugin.GSXR_Get_ControllerHSVersion((int)GCType.Left).ToString(); } else { title.text = "Right Controller"; Text_button_XA.text = "A:"; Text_button_YB.text = "B:"; Version.text = "Version:"+ API_GSXR_Slam.plugin.GSXR_Get_ControllerHSVersion((int)GCType.Right).ToString(); } } protected void ShowControllerData() { if (is_Left) { joyStick.text = GSXR_Get_JoystickValue(GCType.Left).ToString(); if (GSXR_Get_JoystickValue(GCType.Left).x != 8 || GSXR_Get_JoystickValue(GCType.Left).y != 8) { ChangeColor_Green(joyStick); } rotation.text = GSXR_KSRotation(GCType.Left).ToString("f3"); if (GSXR_KSRotation(GCType.Left) != Quaternion.identity) { ChangeColor_Green(rotation); ChangeColor_Green(Text_rotation); } location.text = GSXR_KSPosition(GCType.Left).ToString("f3"); if (GSXR_KSPosition(GCType.Left) != Vector3.zero) { ChangeColor_Green(location); ChangeColor_Green(Text_location); } } else { joyStick.text = GSXR_Get_JoystickValue(GCType.Right).ToString(); if (GSXR_Get_JoystickValue(GCType.Right).x != 8 || GSXR_Get_JoystickValue(GCType.Right).y != 8) { ChangeColor_Green(joyStick); } rotation.text = GSXR_KSRotation(GCType.Right).ToString("f3"); if (GSXR_KSRotation(GCType.Right) != Quaternion.identity) { ChangeColor_Green(rotation); ChangeColor_Green(Text_rotation); } location.text = GSXR_KSPosition(GCType.Right).ToString("f3"); if (GSXR_KSPosition(GCType.Right) != Vector3.zero) { ChangeColor_Green(location); ChangeColor_Green(Text_location); } } } #region Controller Key State protected void KeyDown(InputKeyCode keyCode, InputDevicePartBase part) { if (part.PartType==InputDevicePartType.KSLeft || part.PartType == InputDevicePartType.KSRight) { ShowKeyState(keyCode, "Down"); } } protected void KeyUp(InputKeyCode keyCode, InputDevicePartBase part) { if (part.PartType == InputDevicePartType.KSLeft || part.PartType == InputDevicePartType.KSRight) { ShowKeyState(keyCode, "Up"); } } protected void KeyLong(InputKeyCode keyCode, InputDevicePartBase part) { if (part.PartType == InputDevicePartType.KSLeft || part.PartType == InputDevicePartType.KSRight) { ShowKeyState(keyCode, "Long"); } } protected void KeyTouchEnter(InputKeyCode keyCode, InputDevicePartBase part) { if (part.PartType == InputDevicePartType.KSLeft || part.PartType == InputDevicePartType.KSRight) { ShowTouchKeyState(keyCode, "TouchEnter"); } } protected void KeyTouchExit(InputKeyCode keyCode, InputDevicePartBase part) { if (part.PartType == InputDevicePartType.KSLeft || part.PartType == InputDevicePartType.KSRight) { ShowTouchKeyState(keyCode, "TouchExit"); } } protected void ShowKeyState(InputKeyCode keyCode, string str) { if (is_Left) { switch (keyCode) { case InputKeyCode.X: ControllerKeyState(button_XA2, str); break; case InputKeyCode.Y: ControllerKeyState(button_YB2, str); break; case InputKeyCode.LHallForward: ControllerKeyState(button_Trigger2, str); break; case InputKeyCode.LFunction: ControllerKeyState(button_Function2, str); break; case InputKeyCode.LHallInside: ControllerKeyState(button_Side2, str); break; case InputKeyCode.LjoystickKey: ControllerKeyState(button_JoystickKey2, str); break; default: break; } } else { switch (keyCode) { case InputKeyCode.A: ControllerKeyState(button_XA2, str); break; case InputKeyCode.B: ControllerKeyState(button_YB2, str); break; case InputKeyCode.RHallForward: ControllerKeyState(button_Trigger2, str); break; case InputKeyCode.RFunction: ControllerKeyState(button_Function2, str); break; case InputKeyCode.RHallInside: ControllerKeyState(button_Side2, str); break; case InputKeyCode.RjoystickKey: ControllerKeyState(button_JoystickKey2, str); break; default: break; } } } protected void ShowTouchKeyState(InputKeyCode keyCode, string str) { if (is_Left) { switch (keyCode) { case InputKeyCode.X: ControllerKeyState(button_XA, str); break; case InputKeyCode.Y: ControllerKeyState(button_YB, str); break; case InputKeyCode.LHallForward: ControllerKeyState(button_Trigger, str); break; case InputKeyCode.LFunction: ControllerKeyState(button_Function, str); break; case InputKeyCode.LHallInside: ControllerKeyState(button_Side, str); break; case InputKeyCode.LjoystickKey: ControllerKeyState(button_JoystickKey, str); break; default: break; } } else { switch (keyCode) { case InputKeyCode.A: ControllerKeyState(button_XA, str); break; case InputKeyCode.B: ControllerKeyState(button_YB, str); break; case InputKeyCode.RHallForward: ControllerKeyState(button_Trigger, str); break; case InputKeyCode.RFunction: ControllerKeyState(button_Function, str); break; case InputKeyCode.RHallInside: ControllerKeyState(button_Side, str); break; case InputKeyCode.RjoystickKey: ControllerKeyState(button_JoystickKey, str); break; default: break; } } } protected void ControllerKeyState(TextMeshProUGUI _text, string str) { _text.text = str; } #endregion #region Show Hall Range Value public class HallRangeData { public int deviceID; public int HallFoward; public int HallInside; } public static List TempHallRangeDataList = new List(); [MonoPInvokeCallback(typeof(Action))] static void OnHallRangeEvent(int hall_x, int hall_y, int lr) { TempHallRangeDataList.Add(new HallRangeData() { HallInside = hall_x, HallFoward = hall_y, deviceID = lr }); } protected void UpdateHallRange() { if (TempHallRangeDataList.Count > 0) { if ((is_Left && TempHallRangeDataList[0].deviceID == 0) || (!is_Left && TempHallRangeDataList[0].deviceID == 1)) { Hall_Forward.text = TempHallRangeDataList[0].HallFoward.ToString(); if (TempHallRangeDataList[0].HallFoward != 10) { ChangeColor_Green(Hall_Forward); } Hall_Inside.text = TempHallRangeDataList[0].HallInside.ToString(); if (TempHallRangeDataList[0].HallInside != 10) { ChangeColor_Green(Hall_Inside); } TempHallRangeDataList.RemoveAt(0); } } } #endregion protected void ChangeColor(InputKeyCode keyCode, InputDevicePartBase part) { if (is_Left) { if (keyCode == InputKeyCode.LHallForward) { ChangeColor_Green(button_Trigger); ChangeColor_Green(button_Trigger2); ChangeColor_Green(Text_button_Trigger); } if (keyCode == InputKeyCode.LHallInside) { ChangeColor_Green(button_Side); ChangeColor_Green(button_Side2); ChangeColor_Green(Text_button_Side); } if (keyCode == InputKeyCode.X) { ChangeColor_Green(button_XA); ChangeColor_Green(button_XA2); ChangeColor_Green(Text_button_XA); } if (keyCode == InputKeyCode.Y) { ChangeColor_Green(button_YB); ChangeColor_Green(button_YB2); ChangeColor_Green(Text_button_YB); } if (keyCode == InputKeyCode.LFunction) { ChangeColor_Green(button_Function); ChangeColor_Green(button_Function2); ChangeColor_Green(Text_button_Function); } if (keyCode == InputKeyCode.LjoystickKey) { ChangeColor_Green(button_JoystickKey); ChangeColor_Green(button_JoystickKey2); ChangeColor_Green(Text_button_joystickKey); } } else { if (keyCode == InputKeyCode.RHallForward) { ChangeColor_Green(button_Trigger); ChangeColor_Green(button_Trigger2); ChangeColor_Green(Text_button_Trigger); } if (keyCode == InputKeyCode.RHallInside) { ChangeColor_Green(button_Side); ChangeColor_Green(button_Side2); ChangeColor_Green(Text_button_Side); } if (keyCode == InputKeyCode.A) { ChangeColor_Green(button_XA); ChangeColor_Green(button_XA2); ChangeColor_Green(Text_button_XA); } if (keyCode == InputKeyCode.B) { ChangeColor_Green(button_YB); ChangeColor_Green(button_YB2); ChangeColor_Green(Text_button_YB); } if (keyCode == InputKeyCode.RFunction) { ChangeColor_Green(button_Function); ChangeColor_Green(button_Function2); ChangeColor_Green(Text_button_Function); } if (keyCode == InputKeyCode.RjoystickKey) { ChangeColor_Green(button_JoystickKey); ChangeColor_Green(button_JoystickKey2); ChangeColor_Green(Text_button_joystickKey); } } } protected void ShowDeviceBattery() { if (is_Left) { BatteryLevel.text = "BatteryLevel: " + API_GSXR_Slam.plugin.GSXR_Get_ControllerBattery((int)GCType.Left); } else { BatteryLevel.text = "BatteryLevel: " + API_GSXR_Slam.plugin.GSXR_Get_ControllerBattery((int)GCType.Right); } } protected void ChangeColor_Green(TextMeshProUGUI text) { if (text.color!=Color.green) { text.color = Color.green; } } private void OnDestroy() { API_GSXR_Module_InputSystem.GSXR_KeyDownDelegateUnRegister(ChangeColor); API_GSXR_Module_InputSystem.GSXR_KeyDownDelegateUnRegister(KeyDown); API_GSXR_Module_InputSystem.GSXR_KeyUpDelegateUnRegister(KeyUp); API_GSXR_Module_InputSystem.GSXR_KeyLongDelegateUnRegister(KeyLong); API_GSXR_Module_InputSystem.GSXR_KeyTouchEnterDelegateUnRegister(KeyTouchEnter); API_GSXR_Module_InputSystem.GSXR_KeyTouchExitDelegateUnRegister(KeyTouchExit); API_GSXR_Slam.plugin.GSXR_Set_ControllerHallRangeCallback(null); isOne = true; } }