MoveChange.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using SC.XR.Unity.Module_InputSystem;
  2. using UnityEngine;
  3. public class MoveChange : MonoBehaviour
  4. {
  5. [SerializeField] private GameObject moveGame;
  6. [SerializeField] private Transform parent;
  7. private bool isDown;
  8. private float y;
  9. void Start()
  10. {
  11. moveGame = GameObject.Find("ARSpaceForAll/mesh_test");
  12. parent = GameObject.Find("ARSpaceForAll").transform;
  13. y = moveGame.transform.position.y;
  14. DispatcherBase.KeyDownDelegateRegister(keyDownEventDelegate);
  15. DispatcherBase.KeyUpDelegateRegister(keyUpEventDelegate);
  16. }
  17. private void keyUpEventDelegate(InputKeyCode keyCode, InputDevicePartBase part)
  18. {
  19. if (keyCode != InputKeyCode.Enter)
  20. {
  21. return;
  22. }
  23. Debug.Log("keyDownEventDelegate===>" + keyCode);
  24. moveGame.transform.parent = parent;
  25. isDown = false;
  26. }
  27. private void keyDownEventDelegate(InputKeyCode keyCode, InputDevicePartBase part)
  28. {
  29. if(keyCode != InputKeyCode.Enter)
  30. {
  31. return;
  32. }
  33. if (!SetSceneActive.active)
  34. return;
  35. Debug.Log("keyUpEventDelegate===>" + keyCode);
  36. #if UNITY_EDITOR
  37. moveGame.transform.parent = OpenXRCamera.Instance.head;
  38. #else
  39. switch (DeviceType.type)
  40. {
  41. case "Nreal":
  42. moveGame.transform.parent = API_GSXR_Module_InputSystem_KS.GSXR_KSRight.transform;// OpenXRCamera.Instance.head;
  43. break;
  44. case "A01":
  45. moveGame.transform.parent = OpenXRCamera.Instance.head;
  46. break;
  47. case "Phone":
  48. moveGame.transform.parent = OpenXRCamera.Instance.head;
  49. break;
  50. case "Rhinox":
  51. moveGame.transform.parent = API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDeviceKSPartUI.transform;
  52. break;
  53. default:
  54. moveGame.transform.parent = API_GSXR_Module_InputSystem_KS.GSXR_KSRight.transform;// OpenXRCamera.Instance.head;
  55. break;
  56. }
  57. #endif
  58. isDown = true;
  59. }
  60. void Update()
  61. {
  62. if (isDown && SetSceneActive.active)
  63. {
  64. moveGame.transform.eulerAngles = new Vector3(0, moveGame.transform.eulerAngles.y, 0);
  65. moveGame.transform.position = new Vector3(moveGame.transform.position.x, y, moveGame.transform.position.z);
  66. }
  67. }
  68. }