123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485 |
- 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<HallRangeData> TempHallRangeDataList = new List<HallRangeData>();
- [MonoPInvokeCallback(typeof(Action<int, int, int>))]
- 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;
- }
- }
|