Example #1
0
        /// <summary>
        /// Get state of button corresponding to gaze pointer
        /// </summary>
        /// <returns></returns>
        protected UnityEngine.EventSystems.PointerEventData.FramePressState GetGazeButtonState(OVRInput.Controller activeController)
        {
            var pressed  = false;
            var released = false;

            if (activeController != OVRInput.Controller.None)
            {
                if ((activeController & OVRInput.Controller.Touch) != OVRInput.Controller.None)
                {
                    // Handle touch controllers
                    pressed  = OVRInput.GetDown(joyPadClickButton, activeController);
                    released = OVRInput.GetUp(joyPadClickButton, activeController);
                }
                else if ((activeController & OVRInput.Controller.Hands) != OVRInput.Controller.None &&
                         OVRPlugin.GetHandTrackingEnabled() && null != HandsManager.Instance && HandsManager.Instance.IsInitialized())
                {
                    pressed  = OVRInputHelpers.IsFingerStartPinching(activeController, pinchFinger);
                    released = OVRInputHelpers.IsFingerStopPinching(activeController, pinchFinger);
                }
            }
            else
            {
                pressed  = OVRInput.GetDown(joyPadClickButton);
                released = OVRInput.GetUp(joyPadClickButton);
            }

#if UNITY_ANDROID && !UNITY_EDITOR
            pressed  |= Input.GetMouseButtonDown(0);
            released |= Input.GetMouseButtonUp(0);
#endif

            if (pressed && released)
            {
                return(UnityEngine.EventSystems.PointerEventData.FramePressState.PressedAndReleased);
            }
            if (pressed)
            {
                return(UnityEngine.EventSystems.PointerEventData.FramePressState.Pressed);
            }
            if (released)
            {
                return(UnityEngine.EventSystems.PointerEventData.FramePressState.Released);
            }

            return(UnityEngine.EventSystems.PointerEventData.FramePressState.NotChanged);
        }
Example #2
0
        void ProcessHandPinch(OVRInput.Controller activeController, Transform lastHit,
                              ref Transform triggerDown, ref Transform padDown, ref Transform tertiaryDown)
        {
            // Handle selection callbacks. An object is selected if the button selecting it was
            // pressed AND released while hovering over the object.
            if ((activeController & OVRInput.Controller.Hands) == OVRInput.Controller.None)
            {
                return;
            }

            if (!OVRPlugin.GetHandTrackingEnabled() || !HandsManager.Instance || !HandsManager.Instance.IsInitialized())
            {
                return;
            }

            if (OVRInputHelpers.IsFingerStartPinching(activeController, tertiaryPinchFinger))
            {
                tertiaryDown = lastHit;
            }
            else if (OVRInputHelpers.IsFingerStopPinching(activeController, tertiaryPinchFinger))
            {
                if (tertiaryDown != null && tertiaryDown == lastHit)
                {
                    if (onTertiarySelect != null)
                    {
                        onTertiarySelect.Invoke(tertiaryDown);
                    }
                }
            }
            else if (!OVRInputHelpers.IsFingerPinching(activeController, tertiaryPinchFinger))
            {
                tertiaryDown = null;
            }

            if (OVRInputHelpers.IsFingerStartPinching(activeController, secondaryPinchFinger))
            {
                padDown = lastHit;
            }
            else if (OVRInputHelpers.IsFingerStopPinching(activeController, secondaryPinchFinger))
            {
                if (padDown != null && padDown == lastHit)
                {
                    if (onSecondarySelect != null)
                    {
                        onSecondarySelect.Invoke(padDown);
                    }
                }
            }
            else if (!OVRInputHelpers.IsFingerPinching(activeController, secondaryPinchFinger))
            {
                padDown = null;
            }

            if (OVRInputHelpers.IsFingerStartPinching(activeController, primaryPinchFinger))
            {
                triggerDown = lastHit;
            }
            else if (OVRInputHelpers.IsFingerStopPinching(activeController, primaryPinchFinger))
            {
                if (triggerDown != null && triggerDown == lastHit)
                {
                    if (onPrimarySelect != null)
                    {
                        onPrimarySelect.Invoke(triggerDown);
                    }
                }
            }
            else if (!OVRInputHelpers.IsFingerPinching(activeController, primaryPinchFinger))
            {
                triggerDown = null;
            }
        }