VRControllerLaserCastDummy.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. public class VRControllerLaserCastDummy : VRControllerLaserCast
  5. {
  6. private IEnumerator Start()
  7. {
  8. while (VRTestInputModule.Instance == null)
  9. {
  10. yield return null;
  11. }
  12. VRTestInputModule.Instance.AddController(this);
  13. yield break;
  14. }
  15. private void Update()
  16. {
  17. if (GameMain.Instance == null)
  18. {
  19. return;
  20. }
  21. if (VRTestInputModule.Instance == null)
  22. {
  23. return;
  24. }
  25. if (VRCanvasManager.Instance == null)
  26. {
  27. return;
  28. }
  29. if (this.m_FollowGameObject == null)
  30. {
  31. this.m_FollowGameObject = GameMain.Instance.OvrMgr.OvrCamera.OvrTablet.gameObject;
  32. if (this.m_FollowGameObject == null)
  33. {
  34. return;
  35. }
  36. }
  37. Transform transform = VRCanvasManager.Instance.transform;
  38. Canvas vrcanvas = VRCanvasManager.Instance.GetVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
  39. RectTransform rectTransform = null;
  40. if (vrcanvas)
  41. {
  42. rectTransform = vrcanvas.GetComponent<RectTransform>();
  43. }
  44. Vector3 vector = GameMain.Instance.OvrMgr.SystemUICamera.GetOvrVirtualMouseCurrentSidePos();
  45. vector.x /= 1280f;
  46. vector.y /= 720f;
  47. vector.x -= 0.5f;
  48. vector.y -= 0.5f;
  49. vector.x *= rectTransform.rect.width;
  50. vector.y *= rectTransform.rect.height;
  51. vector.z = -100f;
  52. bool isRotDown = GameMain.Instance.OvrMgr.OvrCamera.OvrTablet.IsRotDown;
  53. bool isSideBack = GameMain.Instance.OvrMgr.OvrCamera.OvrTablet.IsSideBack;
  54. if (isRotDown && !isSideBack)
  55. {
  56. vector.x *= -1f;
  57. vector.y *= -1f;
  58. }
  59. if (!isRotDown && isSideBack)
  60. {
  61. vector.x *= -1f;
  62. }
  63. if (isRotDown && isSideBack)
  64. {
  65. vector.y *= -1f;
  66. }
  67. vector = rectTransform.localToWorldMatrix.MultiplyPoint(vector);
  68. base.transform.position = vector;
  69. }
  70. public override bool GetButtonDown()
  71. {
  72. bool flag = false;
  73. OvrMgr.OvrObject.Controller controller = GameMain.Instance.OvrMgr.ovr_obj.left_controller;
  74. if (controller != null)
  75. {
  76. flag = controller.controller_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_L_CLICK);
  77. }
  78. controller = GameMain.Instance.OvrMgr.ovr_obj.right_controller;
  79. if (controller != null)
  80. {
  81. flag |= controller.controller_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_L_CLICK);
  82. }
  83. return NInput.GetMouseButtonDown(0);
  84. }
  85. public override bool GetButtonUp()
  86. {
  87. bool flag = false;
  88. OvrMgr.OvrObject.Controller controller = GameMain.Instance.OvrMgr.ovr_obj.left_controller;
  89. if (controller != null)
  90. {
  91. flag = controller.controller_buttons.GetPressUp(AVRControllerButtons.BTN.VIRTUAL_L_CLICK);
  92. }
  93. controller = GameMain.Instance.OvrMgr.ovr_obj.right_controller;
  94. if (controller != null)
  95. {
  96. flag |= controller.controller_buttons.GetPressUp(AVRControllerButtons.BTN.VIRTUAL_L_CLICK);
  97. }
  98. return NInput.GetMouseButtonUp(0);
  99. }
  100. public override Vector2 GetScrollDelta()
  101. {
  102. return new Vector2(0f, NInput.GetAxis("Mouse ScrollWheel"));
  103. }
  104. public override bool EnableUIRay()
  105. {
  106. return true;
  107. }
  108. public override void SetRaycastHitPoint(Vector3 WorldPos, Vector3 WorldNormal, float rayLength, GameObject HitObject)
  109. {
  110. }
  111. private GameObject m_FollowGameObject;
  112. }