TouchPadRayPose.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using UnityEngine;
  2. using Rokid.UXR.Module;
  3. using Rokid.UXR.Native;
  4. using Rokid.UXR.Utility;
  5. namespace Rokid.UXR.Interaction
  6. {
  7. public class TouchPadRayPose : BaseRayPose
  8. {
  9. [SerializeField, Tooltip("移动速度")]
  10. private float yaw;
  11. private float pitch;
  12. private float roll;
  13. private void Awake()
  14. {
  15. ResetPose();
  16. TouchPadEventInput.OnActiveTouchPadModule += OnActiveMouseModule;
  17. renderCamera = Camera.main;
  18. }
  19. private void OnDestroy()
  20. {
  21. TouchPadEventInput.OnActiveTouchPadModule -= OnActiveMouseModule;
  22. }
  23. private void OnEnable()
  24. {
  25. TouchPadEventInput.OnMouseMove += OnMouseMove;
  26. }
  27. private void OnDisable()
  28. {
  29. TouchPadEventInput.OnMouseMove -= OnMouseMove;
  30. }
  31. private void OnActiveMouseModule()
  32. {
  33. ResetPose();
  34. }
  35. /// <summary>
  36. /// 重置射线位姿
  37. /// </summary>
  38. private void ResetPose()
  39. {
  40. RKLog.Debug("====TouchPadRayPose====: Reset Pose");
  41. transform.position = MainCameraCache.mainCamera.transform.position;
  42. transform.rotation = MainCameraCache.mainCamera.transform.rotation;
  43. }
  44. private void OnMouseMove(Vector2 delta)
  45. {
  46. if (Utils.IsUnityEditor())
  47. return;
  48. RKLog.Debug("====TouchPadRayPose====:" + delta);
  49. pitch = transform.rotation.eulerAngles.x;
  50. yaw = transform.rotation.eulerAngles.y;
  51. roll = transform.rotation.eulerAngles.z;
  52. pitch += delta.y;
  53. yaw += delta.x;
  54. transform.rotation = Quaternion.Euler(pitch, yaw, 0);
  55. LimitInViewField();
  56. }
  57. #if UNITY_EDITOR
  58. protected override void Update()
  59. {
  60. base.Update();
  61. LimitInViewField();
  62. }
  63. #endif
  64. }
  65. }