Ejemplo n.º 1
0
        void ProcessGazePointer(WinMRPointerEventData pointerEvent, out bool fired)
        {
            fired = false;
            if (pointerEvent.pointerEnter != null)
            {
                // if the ui receiver has changed, reset the gaze delay timer
                GameObject handler = ExecuteEvents.GetEventHandler <IPointerClickHandler>(pointerEvent.pointerEnter);
                if (currentLookAtHandler != handler)
                {
                    currentLookAtHandler          = handler;
                    currentLookAtHandlerClickTime = Time.unscaledTime + TimeToGazeClick;
                }

                // if we have a handler and it's time to click, do it now
                if (currentLookAtHandler != null && Time.unscaledTime > currentLookAtHandlerClickTime)
                {
                    ExecuteEvents.ExecuteHierarchy(currentLookAtHandler, pointerEvent, ExecuteEvents.pointerClickHandler);
                    currentLookAtHandlerClickTime = float.MaxValue;
                    fired = true;
                    pointerEvent.clickTime = Time.unscaledTime;
                }
            }
            else
            {
                currentLookAtHandler = null;
            }
        }
Ejemplo n.º 2
0
        void DoRandomHitTesting(WinMRPointerEventData data)
        {
            Ray ray = new Ray(data.pointerCurrentRaycast.worldPosition, data.pointerCurrentRaycast.worldNormal);

            Debug.DrawRay(ray.origin, ray.direction, Color.green);
            RaycastHit raycastHit;

            if (Physics.Raycast(ray, out raycastHit, 10f))
            {
                if (raycastHit.collider != null)
                {
                    Debug.Log("hit: " + raycastHit.collider.gameObject.name);
                }
            }

            RaycastHit2D hit2D = Physics2D.Raycast(ray.origin, ray.direction, 10f);

            if (hit2D.collider != null)
            {
                Debug.Log("hit: " + hit2D.collider.gameObject.name);
            }

            var rayCasterList = GameObject.FindObjectsOfType <UnityEngine.UI.GraphicRaycaster>();

            if (rayCasterList != null)
            {
                List <RaycastResult> results = new List <RaycastResult>();
                foreach (UnityEngine.UI.GraphicRaycaster rc in rayCasterList)
                {
                    rc.Raycast(data, results);
                    if (results.Count > 0)
                    {
                        foreach (var result in results)
                        {
                            Debug.Log(string.Format("result - valid ({0}), object({1}), module({2})",
                                                    result.isValid, (result.gameObject == null) ? "null" : result.gameObject.name, result.module.name));
                        }
                    }
                }
            }
        }