Example #1
0
        public override void Process()
        {
            InputSource activeSource = null;

            if (UseMotionControllerForPosition)
            {
                activeSource = GetActiveMotionController();
            }
            else
            {
                Debug.Assert(UseGazeForPosition, "Expected UseGazeForPosition to be default/fallback");
                activeSource = GetGazeSource();
            }


            if (activeSource != null)
            {
                if (activeSource.pointerEvent == null)
                {
                    activeSource.pointerEvent = new WinMRPointerEventData(eventSystem);
                }
                else
                {
                    activeSource.pointerEvent.Reset();
                }

                activeSource.pointerEvent.delta = Vector2.zero;


                if (AllowGamepadControllerForSelect)
                {
                    UpdateGamepadState(ref activeSource);
                }

                if (UseMotionControllerForPosition)
                {
                    activeSource.pointerEvent.pointerCurrentRaycast = new RaycastResult()
                    {
                        worldPosition = activeSource.Position,
                        worldNormal   = activeSource.ForwardPointer
                    };
                }
                else if (UseGazeForPosition)
                {
                    activeSource.pointerEvent.position = new Vector2(UnityEngine.XR.XRSettings.eyeTextureWidth / 2, UnityEngine.XR.XRSettings.eyeTextureHeight / 2);
                    activeSource.pointerEvent.pointerCurrentRaycast = new RaycastResult()
                    {
                        worldPosition = Camera.main.transform.position,
                        worldNormal   = Camera.main.transform.forward
                    };
                }

                // trigger a raycast
                ProcessRaycast(activeSource);


                GameObject currentTargetGO = null;
                if (activeSource.pointerEvent.pointerCurrentRaycast.isValid)
                {
                    currentTargetGO = activeSource.pointerEvent.pointerCurrentRaycast.gameObject;
                }

                // Handle enter and exit events on the GUI controlls that are hit
                base.HandlePointerExitAndEnter(activeSource.pointerEvent, currentTargetGO);

                bool firedOnGaze;
                if (UseGazeForSelect)
                {
                    ProcessGazePointer(activeSource.pointerEvent, out firedOnGaze);
                }
                else if (activeSource.IsSelectPressed && currentTargetGO != null)
                {
                    DeselectIfSelectionChanged(currentTargetGO, activeSource.pointerEvent);
                    if ((Time.unscaledTime - activeSource.pointerEvent.clickTime) > MinimumTimeBetweenClicksAcrossAll)
                    {
                        activeSource.pointerEvent.current         = currentTargetGO;
                        activeSource.pointerEvent.rawPointerPress = currentTargetGO;
                        GameObject newPressed       = ExecuteEvents.ExecuteHierarchy(currentTargetGO, activeSource.pointerEvent, ExecuteEvents.pointerDownHandler);
                        bool       needsToFireClick = true;
                        if (newPressed == null)
                        {
                            // some UI elements might only have click handler and not pointer down handler
                            newPressed = ExecuteEvents.ExecuteHierarchy(currentTargetGO, activeSource.pointerEvent, ExecuteEvents.pointerClickHandler);
                            activeSource.pointerEvent.clickTime    = Time.unscaledTime;
                            activeSource.pointerEvent.pointerPress = newPressed;
                            needsToFireClick = false; // not needed, optimizer shall remove
                        }
                        else
                        {
                            activeSource.pointerEvent.pointerPress = newPressed;
                            // Same button, but maybe different time, possibly two presses it enough time between click
                            if (activeSource.pointerEvent.pointerPress == activeSource.pointerEvent.lastPress)
                            {
                                if ((Time.unscaledTime - activeSource.pointerEvent.clickTime) < MinimumTimeBetweenClicksSameControl)
                                {
                                    needsToFireClick = false;
                                    activeSource.pointerEvent.clickCount++;
#if TRACING_VERBOSE
                                    Debug.Log("Same control debounce at " + activeSource.pointerEvent.pointerPress.name);
#endif
                                }
                                // no else because we fall back to firing as a new event (via needsToFireClick == true )
                            }

                            if (needsToFireClick)
                            {
                                activeSource.pointerEvent.clickTime  = Time.unscaledTime;
                                activeSource.pointerEvent.clickCount = 1;
#if TRACING_VERBOSE
                                Debug.Log("Firing Click for " + newPressed.name);
#endif
                                ExecuteEvents.Execute(newPressed, activeSource.pointerEvent, ExecuteEvents.pointerClickHandler);
                            }
                        }
                    }

#if TRACING_VERBOSE
                    else
                    {
                        //  Debug.Log("Skipped click due to hardware debounce" + currentTargetGO.name);
                    }
#endif
                }
                else if (currentTargetGO == null && eventSystem.currentSelectedGameObject)
                {
#if TRACING_VERBOSE
                    Debug.Log("***Clearing selection***");
#endif
                    DeselectIfSelectionChanged(currentTargetGO, activeSource.pointerEvent);
                }

                if (activeSource.IsSelectRelased)
                {
                    if (activeSource.pointerEvent.pointerPress != null) /// data.pointerEvent.pointerPress
                    {
#if TRACING_VERBOSE
                        Debug.Log("Pointer Up" + activeSource.pointerEvent.pointerPress.name);
#endif
                        ExecuteEvents.Execute(activeSource.pointerEvent.pointerPress, activeSource.pointerEvent, ExecuteEvents.pointerUpHandler);
                        // data.pointerEvent.rawPointerPress = null;
                        //  data.pointerEvent.pointerPress = null;
                    }
                    activeSource.IsMotionControllerSelectReleased = false;
                }

                if (activeSource.IsMotionControllerSelectPressed)
                {
                    activeSource.IsMotionControllerSelectPressed = false;
                }
            }
        }
Example #2
0
 void ProcessRaycast(InputSource data)
 {
     eventSystem.RaycastAll(data.pointerEvent, m_RaycastResultCache);
     data.pointerEvent.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache);
     m_RaycastResultCache.Clear();
 }