public void CheckController(SteamVR_TrackedObject controller) { SteamVR_Controller.Device input = null; if (controller != null) { input = SteamVR_Controller.Input((int)controller.index); } Vector3 origin; Vector3 direction; Quaternion rotation; origin = controller.transform.position; direction = controller.transform.rotation * new Vector3(0, 0, 100); rotation = controller.transform.rotation; bool hitScreen = false; // Mouse simulation if (Visible()) { RaycastHit[] rcasts = Physics.RaycastAll(origin, direction); foreach (RaycastHit rcast in rcasts) { if (rcast.collider.gameObject != this.gameObject) { continue; } hitScreen = true; if (m_manager.ShowLine) { m_line.enabled = true; m_line.SetPosition(0, origin); m_line.SetPosition(1, rcast.point); } else { m_line.enabled = false; } float dx = m_manager.GetScreenWidth(Screen); float dy = m_manager.GetScreenHeight(Screen); float vx = rcast.textureCoord.x; float vy = rcast.textureCoord.y; vy = 1 - vy; float x = (vx * dx); float y = (vy * dy); int iX = (int)x; int iY = (int)y; m_manager.SetCursorPos(iX, iY); if (m_lastShowClick == 0) { //if (m_manager.EnableZoom) if (m_manager.ViveZoom != VdmDesktopManager.ViveButton.None) { if (OVRInput.GetPressDown(MyButtonToViveButton(m_manager.ViveZoom))) { VdmDesktopManager.ActionInThisFrame = true; m_distanceBeforeZoom = (controller.transform.position - rcast.point).magnitude; float distanceDelta = m_distanceBeforeZoom - m_manager.ControllerZoomDistance; Vector3 vectorMove = rotation * new Vector3(0, 0, -distanceDelta); m_positionZoomed = m_positionNormal + vectorMove; m_rotationZoomed = m_rotationNormal; //m_positionZoomed = controller.transform.position + controller.transform.rotation * new Vector3(0, 0, m_manager.ControllerZoomDistance); ZoomIn(); } if (OVRInput.GetPressUp(MyButtonToViveButton(m_manager.ViveZoom))) { VdmDesktopManager.ActionInThisFrame = true; ZoomOut(); } } } if (m_manager.ViveLeftClick != VdmDesktopManager.ViveButton.None) { if (OVRInput.GetPressDown(MyButtonToViveButton(m_manager.ViveLeftClick))) { m_lastLeftTriggerClick = Time.time; m_manager.SimulateMouseLeftDown(); VdmDesktopManager.ActionInThisFrame = true; } if (OVRInput.GetPressUp(MyButtonToViveButton(m_manager.ViveLeftClick))) { if (m_lastLeftTriggerClick != 0) { m_manager.SimulateMouseLeftUp(); m_lastLeftTriggerClick = 0; VdmDesktopManager.ActionInThisFrame = true; } } } if (m_manager.ViveTouchPadForClick) { if (OVRInput.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad) && (OVRInput.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0).x < -0.2f)) { m_lastLeftTouchClick = Time.time; m_manager.SimulateMouseLeftDown(); VdmDesktopManager.ActionInThisFrame = true; } if (OVRInput.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad) && (OVRInput.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0).x > -0.2f)) { m_lastRightTouchClick = Time.time; m_manager.SimulateMouseRightDown(); VdmDesktopManager.ActionInThisFrame = true; } } if (m_lastLeftTouchClick != 0) { if (OVRInput.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { m_manager.SimulateMouseLeftUp(); m_lastLeftTouchClick = 0; VdmDesktopManager.ActionInThisFrame = true; } } if (m_lastRightTouchClick != 0) { if (OVRInput.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { m_manager.SimulateMouseRightUp(); m_lastRightTouchClick = 0; VdmDesktopManager.ActionInThisFrame = true; } } } } if ((Visible() == false) || (hitScreen)) { if (OVRInput.GetPressDown(MyButtonToViveButton(m_manager.ViveShow))) { if (m_lastShowClick == 0) { VdmDesktopManager.ActionInThisFrame = true; if (hitScreen == false) { Show(); // Don't set m_positionNormal. Vector3 startDistance = controller.transform.rotation * new Vector3(0, 0, m_manager.ControllerZoomDistance); transform.position = controller.transform.position + startDistance; transform.rotation = controller.transform.rotation; m_lastShowClick = Time.time - 10; } else { m_lastShowClick = Time.time; } transform.SetParent(controller.transform); m_controllerAttach = true; } } } if (OVRInput.GetPressUp(MyButtonToViveButton(m_manager.ViveShow))) { if (m_lastShowClick != 0) { if (Time.time - m_lastShowClick < 0.5f) { Hide(); } VdmDesktopManager.ActionInThisFrame = true; m_lastShowClick = 0; transform.SetParent(m_manager.transform); m_controllerAttach = false; m_positionNormal = transform.position; m_rotationNormal = transform.rotation; } } }