public static void AddRaycaster(NRPointerRaycaster raycaster) { if (raycaster == null) { return; } Initialize(); raycasters.Add(raycaster); }
public override void GraphicRaycast(Canvas canvas, bool ignoreReversedGraphics, Ray ray, float distance, NRPointerRaycaster 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 NRButton. var button = graphic.gameObject.GetComponent <NRButton>(); if (button != null) { button.OnHover(racastResult); } } }
public static void RemoveRaycaster(NRPointerRaycaster raycaster) { raycasters.Remove(raycaster); }
public NRPointerEventData(NRPointerRaycaster raycaster, EventSystem eventSystem) : base(eventSystem) { this.raycaster = raycaster; }
private void GraphicRaycast(Canvas canvas, bool ignoreReversedGraphics, Ray ray, float distance, NRPointerRaycaster raycaster, List <RaycastResult> raycastResults) { if (canvas == null) { return; } var eventCamera = raycaster.eventCamera; var screenCenterPoint = NRInputModule.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 }); } }