/// <summary> /// Get state of button corresponding to gaze pointer /// </summary> /// <returns></returns> protected PointerEventData.FramePressState GetGazeButtonState() { var pressed = Input.GetKeyDown(gazeClickKey) || OVRInput.GetDown(joyPadClickButton); var released = Input.GetKeyUp(gazeClickKey) || OVRInput.GetUp(joyPadClickButton); #if UNITY_ANDROID && !UNITY_EDITOR pressed |= Input.GetMouseButtonDown(0); released |= Input.GetMouseButtonUp(0); #endif if (pressed && released) { return(PointerEventData.FramePressState.PressedAndReleased); } if (pressed) { return(PointerEventData.FramePressState.Pressed); } if (released) { return(PointerEventData.FramePressState.Released); } return(PointerEventData.FramePressState.NotChanged); }
// Overridden so that we can process the two types of pointer separately // The following 2 functions are equivalent to PointerInputModule.GetMousePointerEventData but are customized to // get data for ray pointers and canvas mouse pointers. /// <summary> /// State for a pointer controlled by a world space ray. E.g. gaze pointer /// </summary> /// <returns></returns> protected MouseState GetGazePointerData() { // Get the OVRRayPointerEventData reference OVRRayPointerEventData leftData; GetPointerData(kMouseLeftId, out leftData, true); leftData.Reset(); //Now set the world space ray. This ray is what the user uses to point at UI elements //warrick: Alter line below to change what element is pointed at. leftData.worldSpaceRay = new Ray(rayTransform.position, rayTransform.forward); leftData.scrollDelta = GetExtraScrollDelta(); //Populate some default values leftData.button = PointerEventData.InputButton.Left; leftData.useDragThreshold = true; // Perform raycast to find intersections with world eventSystem.RaycastAll(leftData, m_RaycastResultCache); var raycast = FindFirstRaycast(m_RaycastResultCache); //warrick: If there's no game object hit by any ray then teleport. if (!raycast.isValid && OVRInput.GetDown(OVRInput.Button.One)) { Debug.Log("nothing hit. Teleporting forward"); rayTransform.root.position = leftData.worldSpaceRay.origin + leftData.worldSpaceRay.direction * teleportDistance; } leftData.pointerCurrentRaycast = raycast; m_RaycastResultCache.Clear(); OVRRaycaster ovrRaycaster = raycast.module as OVRRaycaster; // We're only interested in intersections from OVRRaycasters if (ovrRaycaster) { // The Unity UI system expects event data to have a screen position // so even though this raycast came from a world space ray we must get a screen // space position for the camera attached to this raycaster for compatability leftData.position = ovrRaycaster.GetScreenPosition(raycast); // Find the world position and normal the Graphic the ray intersected RectTransform graphicRect = raycast.gameObject.GetComponent <RectTransform>(); if (graphicRect != null) { // Set are gaze indicator with this world position and normal Vector3 worldPos = raycast.worldPosition; Vector3 normal = GetRectTransformNormal(graphicRect); OVRGazePointer.instance.SetPosition(worldPos, normal); // Make sure it's being shown OVRGazePointer.instance.RequestShow(); } } OVRPhysicsRaycaster physicsRaycaster = raycast.module as OVRPhysicsRaycaster; if (physicsRaycaster) { leftData.position = physicsRaycaster.GetScreenPos(raycast.worldPosition); OVRGazePointer.instance.RequestShow(); OVRGazePointer.instance.SetPosition(raycast.worldPosition, raycast.worldNormal); } // Stick default data values in right and middle slots for compatability // copy the apropriate data into right and middle slots OVRRayPointerEventData rightData; GetPointerData(kMouseRightId, out rightData, true); CopyFromTo(leftData, rightData); rightData.button = PointerEventData.InputButton.Right; OVRRayPointerEventData middleData; GetPointerData(kMouseMiddleId, out middleData, true); CopyFromTo(leftData, middleData); middleData.button = PointerEventData.InputButton.Middle; m_MouseState.SetButtonState(PointerEventData.InputButton.Left, GetGazeButtonState(), leftData); m_MouseState.SetButtonState(PointerEventData.InputButton.Right, PointerEventData.FramePressState.NotChanged, rightData); m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, PointerEventData.FramePressState.NotChanged, middleData); return(m_MouseState); }
/// <summary> /// Get state of button corresponding to gaze pointer /// </summary> /// <returns></returns> virtual protected PointerEventData.FramePressState GetGazeButtonState() { var pressed = Input.GetKeyDown(gazeClickKey) || OVRInput.GetDown(joyPadClickButton, OVRInput.Controller.RTouch) || OVRInput.GetDown(joyPadClickButton, OVRInput.Controller.LTouch); var released = Input.GetKeyUp(gazeClickKey) || OVRInput.GetDown(joyPadClickButton, OVRInput.Controller.RTouch) || OVRInput.GetDown(joyPadClickButton, OVRInput.Controller.LTouch); /* #if UNITY_ANDROID && !UNITY_EDITOR * pressed |= Input.GetMouseButtonDown(0); * released |= Input.GetMouseButtonUp(0); #endif */ if (pressed && released) { return(PointerEventData.FramePressState.PressedAndReleased); } if (pressed) { return(PointerEventData.FramePressState.Pressed); } if (released) { return(PointerEventData.FramePressState.Released); } return(PointerEventData.FramePressState.NotChanged); }