SwitchMode.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using SC.XR.Unity;
  2. using SC.XR.Unity.Module_InputSystem;
  3. using SC.XR.Unity.Module_InputSystem.InputDeviceGC.KS;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. public class SwitchMode : MonoBehaviour
  9. {
  10. bool is6Dof = true;
  11. // Start is called before the first frame update
  12. void Start()
  13. {
  14. API_GSXR_Module_InputSystem.GSXR_KeyDownDelegateRegister(Set6DofBtn);
  15. }
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. }
  20. private void OnDestroy()
  21. {
  22. API_GSXR_Module_InputSystem.GSXR_KeyDownDelegateUnRegister(Set6DofBtn);
  23. }
  24. InputDeviceKSPart kspart;
  25. InputDeviceKS ks;
  26. public void Set6DofBtn(InputKeyCode inputKeyCode,InputDevicePartBase part)
  27. {
  28. if (part.inputDeviceBase.inputDeviceType == InputDeviceType.KS && (inputKeyCode == InputKeyCode.A||inputKeyCode==InputKeyCode.X))
  29. {
  30. is6Dof = !is6Dof;
  31. SetMode(is6Dof);
  32. }
  33. }
  34. public void SetMode(bool is6dof)
  35. {
  36. API_GSXR_Slam.plugin.GSXR_Set_6Dof(is6dof);
  37. ks = API_GSXR_Module_InputSystem_KS.GSXR_KSDevice;
  38. foreach (var item in ks.inputDevicePartList)
  39. {
  40. kspart = item as InputDeviceKSPart;
  41. if (!is6dof)
  42. {
  43. kspart.inputDataGetKS.inputDataGetKSPosture.isKS_3DofMode = true;
  44. kspart.inputDeviceKSPartUI.ModelGC._modelPositionDeltaWithDevice.z = 0.15f;
  45. kspart.inputDataKS.PostureType = SC.XR.Unity.Module_InputSystem.InputDeviceGC.PostureType._3Dof;
  46. kspart.inputDataGetKS.inputDataGetKSPosture.delayOffset = -(Vector3.forward * 0.3f);
  47. }
  48. else
  49. {
  50. kspart.inputDataGetKS.inputDataGetKSPosture.isKS_3DofMode = false;
  51. kspart.inputDataKS.PostureType = SC.XR.Unity.Module_InputSystem.InputDeviceGC.PostureType._6Dof;
  52. kspart.inputDeviceKSPartUI.ModelGC._modelPositionDeltaWithDevice.z = 0.0f;
  53. kspart.inputDataGetKS.inputDataGetKSPosture.delayOffset = Vector3.zero;
  54. }
  55. }
  56. }
  57. }