ThreeDofRayPose.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Rokid.UXR.Utility;
  2. using UnityEngine;
  3. namespace Rokid.UXR.Interaction
  4. {
  5. public class ThreeDofRayPose : BaseRayPose
  6. {
  7. private FollowCamera followCamera;
  8. private HandType handType;
  9. protected override void Start()
  10. {
  11. base.Start();
  12. followCamera = this.GetComponent<FollowCamera>();
  13. ThreeDofEventInput.OnPhoneRayForward += OnPhoneRayForward;
  14. // ThreeDofEventInput.Instance.ResetImuAxisY();
  15. this.handType = ThreeDofEventInput.Instance.HandType;
  16. InitHandType(handType);
  17. }
  18. private void OnDestroy()
  19. {
  20. ThreeDofEventInput.OnPhoneRayForward -= OnPhoneRayForward;
  21. }
  22. private void OnPhoneRayForward(Vector3 forward)
  23. {
  24. if (Utils.IsUnityEditor())
  25. return;
  26. this.transform.eulerAngles = forward;
  27. }
  28. protected override void Update()
  29. {
  30. base.Update();
  31. if (ThreeDofEventInput.Instance.HandType != handType)
  32. {
  33. handType = ThreeDofEventInput.Instance.HandType;
  34. InitHandType(handType);
  35. }
  36. }
  37. private void InitHandType(HandType handType)
  38. {
  39. // if (Utils.IsAndroidPlatfrom())
  40. // {
  41. // switch (handType)
  42. // {
  43. // case HandType.None:
  44. // followCamera.offsetPosition = new Vector3(0, -0.5f, 0);
  45. // break;
  46. // case HandType.LeftHand:
  47. // followCamera.offsetPosition = new Vector3(-0.1f, -0.5f, 0);
  48. // break;
  49. // case HandType.RightHand:
  50. // followCamera.offsetPosition = new Vector3(0.1f, -0.5f, 0);
  51. // break;
  52. // }
  53. // }
  54. }
  55. }
  56. }