Esempio n. 1
0
 protected virtual void OnEnable()
 {
     m_raycaster = GetComponent <Pointer3DRaycaster>();
     if (m_raycaster != null)
     {
         m_raycaster.AddRaycastMethod(this);
     }
 }
Esempio n. 2
0
 protected virtual void OnDestroy()
 {
     if (m_raycaster != null)
     {
         raycaster.RemoveRaycastMethod(this);
     }
     m_raycaster = null;
 }
Esempio n. 3
0
 protected virtual void OnDestroy()
 {
     if (m_raycaster != null)
     {
         raycaster.RemoveGenerator(this);
     }
     m_raycaster = null;
 }
Esempio n. 4
0
 protected virtual void Start()
 {
     m_raycaster = GetComponent <Pointer3DRaycaster>();
     if (m_raycaster != null)
     {
         m_raycaster.AddGenerator(this);
     }
 }
Esempio n. 5
0
        public static bool TryGetRaycaster3D(this PointerEventData eventData, out Pointer3DRaycaster raycaster)
        {
            raycaster = null;

            if (!(eventData is Pointer3DEventData))
            {
                return(false);
            }

            var eventData3D = eventData as Pointer3DEventData;

            raycaster = eventData3D.raycaster;
            return(true);
        }
Esempio n. 6
0
        public static void Raycast(Canvas canvas, bool ignoreReversedGraphics, Ray ray, float distance, Pointer3DRaycaster raycaster, List <RaycastResult> raycastResults)
        {
            if (canvas == null)
            {
                return;
            }

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

            // Pointer3DRaycaster should set tje eventCamera to correct position

            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;
                }

                //var dist = Vector3.Dot(transForward, trans.position - ray.origin) / Vector3.Dot(transForward, ray.direction);
                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
                });
            }
        }
Esempio n. 7
0
 public StandaloneEventData(Pointer3DRaycaster ownerRaycaster, EventSystem eventSystem, StandaloneButton sbtn, InputButton ibtn) : base(ownerRaycaster, eventSystem)
 {
     standaloneButton = sbtn;
     button           = ibtn;
 }
Esempio n. 8
0
 public Pointer3DEventData(Pointer3DRaycaster ownerRaycaster, EventSystem eventSystem) : base(eventSystem)
 {
     raycaster = ownerRaycaster;
     InputModule.AssignPointerId(this);
 }