/// <summary> /// 手指检测最近的平面 /// </summary> private bool FingerRaycast(XRPointEventData eventData, out Vector3 raycasterDirection) { raycasterDirection = Vector3.forward; if (UICanvas == null) { return(false); } if (UICanvas.renderMode == RenderMode.ScreenSpaceOverlay) { return(false); } var canvasGraphics = GraphicRegistry.GetGraphicsForCanvas(UICanvas); if (canvasGraphics == null || canvasGraphics.Count == 0) { return(false); } float maxSqrDistance = eventData.hitDistance * eventData.hitDistance; int lengthOfGraphics = canvasGraphics.Count; float minSqrDistance = maxSqrDistance + 1f; for (int i = 0; i < lengthOfGraphics; i++) { Graphic graphic = canvasGraphics[i]; if (graphic.depth == -1 || !graphic.raycastTarget || graphic.canvasRenderer.cull) { continue; } RectTransform rectTransform = graphic.rectTransform; if (ignoreReversedGraphics) { var rayDir = eventData.origin - rectTransform.position; if (Vector3.Dot(rayDir, rectTransform.forward) > 0) { continue; } } float sqrDistance = maxSqrDistance + 1; if (rectTransform.InRectangle(eventData.origin, out sqrDistance)) { if (sqrDistance < minSqrDistance && sqrDistance <= maxSqrDistance) { minSqrDistance = sqrDistance; raycasterDirection = rectTransform.forward; } } } return(minSqrDistance <= maxSqrDistance); }
private bool GetFingerPointerData(int id, out XRPointEventData data, bool create) { if (!m_FingerPointerData.TryGetValue(id, out data) && create) { data = new XRPointEventData(eventSystem) { pointerId = id, }; m_FingerPointerData.Add(id, data); return(true); } return(false); }
private MouseButtonEventData GetLaserPointerEventData(LaserPointer laser) { MouseButtonEventData mouseButtonData; var created = GetLaserPointerData(laser.fingerId, out mouseButtonData, true); XRPointEventData pointerData = mouseButtonData.buttonData as XRPointEventData; pointerData.Reset(); pointerData.origin = laser.origin; pointerData.direction = laser.direction; pointerData.hitDistance = laser.raycastDistance; pointerData.button = PointerEventData.InputButton.Left; pointerData.raycastCamera = laser.raycastCamera; pointerData.position = new Vector2(laser.raycastCamera.pixelWidth * 0.5f, laser.raycastCamera.pixelHeight * 0.5f); pointerData.useFingerRaycast = false; eventSystem.RaycastAll(pointerData, m_RaycastResultCache); var raycast = FindFirstRaycast(m_RaycastResultCache); pointerData.pointerCurrentRaycast = raycast; m_RaycastResultCache.Clear(); //更新射线状态 laser.UpdateStateFormRaycast(ref raycast); mouseButtonData.buttonState = XRPointEventData.StateForButton(laser.isPressed, laser.isReleased); if (laser.isHit) { if (created) { pointerData.hitPoint = laser.hitPoint; } pointerData.scrollDelta = laser.scrollDelta; pointerData.delta = laser.delta; pointerData.hitNormal = laser.hitNormal; pointerData.hitPoint = laser.hitPoint; } return(mouseButtonData); }
private void RecordPressedPosition(XRPointEventData eventData) { eventData.pressHitPosition = eventData.hitPoint; }
/// <summary> /// 手指检测最近的平面 /// 优化: /// </summary> private bool FingerRaycast(XRPointEventData eventData, ref Vector3 nearGrapicNormal) { return(false); }