Ejemplo n.º 1
0
 public static void AddRaycaster(TXRPointerRaycaster raycaster)
 {
     if (raycaster == null)
     {
         return;
     }
     Initialize();
     raycasters.Add(raycaster);
 }
Ejemplo n.º 2
0
 public static void RemoveRaycaster(TXRPointerRaycaster raycaster)
 {
     raycasters.Remove(raycaster);
 }
        public override void GraphicRaycast(Canvas canvas, bool ignoreReversedGraphics, Ray ray, float distance, TXRPointerRaycaster raycaster, List <RaycastResult> raycastResults)
        {
            if (canvas == null)
            {
                return;
            }

            var eventCamera       = raycaster.eventCamera;
            var screenCenterPoint = eventCamera.WorldToScreenPoint(eventCamera.transform.position); //new Vector2(m_ScreenWidth * 0.5f, m_ScreenHeight * 0.5f + 1800);
            var graphics          = GraphicRegistry.GetGraphicsForCanvas(canvas);

            for (int i = 0; i < graphics.Count; ++i)
            {
                var graphic = graphics[i];
                // -1 means it hasn't been processed by the canvas, which means it isn't actually drawn
                if (graphic.depth == -1 || !graphic.raycastTarget)
                {
                    continue;
                }

                if (!RectTransformUtility.RectangleContainsScreenPoint(graphic.rectTransform, screenCenterPoint, eventCamera))
                {
                    continue;
                }

                if (ignoreReversedGraphics && Vector3.Dot(ray.direction, graphic.transform.forward) <= 0f)
                {
                    continue;
                }

                if (!graphic.Raycast(screenCenterPoint, eventCamera))
                {
                    continue;
                }

                float dist;
                new Plane(graphic.transform.forward, graphic.transform.position).Raycast(ray, out dist);
                if (dist > distance)
                {
                    continue;
                }
                var racastResult = new RaycastResult
                {
                    gameObject     = graphic.gameObject,
                    module         = raycaster,
                    distance       = dist,
                    worldPosition  = ray.GetPoint(dist),
                    worldNormal    = -graphic.transform.forward,
                    screenPosition = screenCenterPoint,
                    index          = raycastResults.Count,
                    depth          = graphic.depth,
                    sortingLayer   = canvas.sortingLayerID,
                    sortingOrder   = canvas.sortingOrder
                };
                raycastResults.Add(racastResult);

                // Send onhover event to TXRButton.
                var button = graphic.gameObject.GetComponent <TXRButton>();
                if (button != null)
                {
                    button.OnHover(racastResult);
                }
            }
        }
        public virtual void GraphicRaycast(Canvas canvas, bool ignoreReversedGraphics, Ray ray, float distance, TXRPointerRaycaster raycaster, List <RaycastResult> raycastResults)
        {
            if (canvas == null)
            {
                return;
            }

            var eventCamera       = raycaster.eventCamera;
            var screenCenterPoint = TXRInputModule.ScreenCenterPoint;
            var graphics          = GraphicRegistry.GetGraphicsForCanvas(canvas);

            for (int i = 0; i < graphics.Count; ++i)
            {
                var graphic = graphics[i];

                // -1 means it hasn't been processed by the canvas, which means it isn't actually drawn
                if (graphic.depth == -1 || !graphic.raycastTarget)
                {
                    continue;
                }

                if (!RectTransformUtility.RectangleContainsScreenPoint(graphic.rectTransform, screenCenterPoint, eventCamera))
                {
                    continue;
                }

                if (ignoreReversedGraphics && Vector3.Dot(ray.direction, graphic.transform.forward) <= 0f)
                {
                    continue;
                }

                if (!graphic.Raycast(screenCenterPoint, eventCamera))
                {
                    continue;
                }

                float dist;
                new Plane(graphic.transform.forward, graphic.transform.position).Raycast(ray, out dist);
                if (dist > distance)
                {
                    continue;
                }

                raycastResults.Add(new RaycastResult
                {
                    gameObject     = graphic.gameObject,
                    module         = raycaster,
                    distance       = dist,
                    worldPosition  = ray.GetPoint(dist),
                    worldNormal    = -graphic.transform.forward,
                    screenPosition = screenCenterPoint,
                    index          = raycastResults.Count,
                    depth          = graphic.depth,
                    sortingLayer   = canvas.sortingLayerID,
                    sortingOrder   = canvas.sortingOrder
                });
            }
        }
 public TXRPointerEventData(TXRPointerRaycaster raycaster, EventSystem eventSystem) : base(eventSystem)
 {
     this.raycaster = raycaster;
 }