ButtonMouseRayPose.cs 2.1 KB

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