private bool IsHovering(VRUIPointer pointer) { foreach (var hoveredObject in pointer.pointerEventData.hovered) { if (pointer.pointerEventData.pointerEnter && hoveredObject && CheckTransformTree(hoveredObject.transform, pointer.pointerEventData.pointerEnter.transform)) { return(true); } } return(false); }
private void Hover(VRUIPointer pointer, List <RaycastResult> results) { if (pointer.pointerEventData.pointerEnter) { if (NoValidCollision(pointer, results)) { ExecuteEvents.ExecuteHierarchy(pointer.pointerEventData.pointerEnter, pointer.pointerEventData, ExecuteEvents.pointerExitHandler); pointer.pointerEventData.hovered.Remove(pointer.pointerEventData.pointerEnter); pointer.pointerEventData.pointerEnter = null; } } else { foreach (var result in results) { var target = ExecuteEvents.ExecuteHierarchy(result.gameObject, pointer.pointerEventData, ExecuteEvents.pointerEnterHandler); if (target != null) { var selectable = target.GetComponent <Selectable>(); if (selectable) { var noNavigation = new Navigation(); noNavigation.mode = Navigation.Mode.None; selectable.navigation = noNavigation; } pointer.OnUIPointerElementEnter(pointer.SetUIPointerEvent(target, pointer.hoveringElement)); pointer.hoveringElement = target; pointer.pointerEventData.pointerCurrentRaycast = result; pointer.pointerEventData.pointerEnter = target; pointer.pointerEventData.hovered.Add(pointer.pointerEventData.pointerEnter); break; } else { if (result.gameObject != pointer.hoveringElement) { pointer.OnUIPointerElementEnter(pointer.SetUIPointerEvent(result.gameObject, pointer.hoveringElement)); } pointer.hoveringElement = result.gameObject; } } if (pointer.hoveringElement && results.Count == 0) { pointer.OnUIPointerElementExit(pointer.SetUIPointerEvent(null, pointer.hoveringElement)); pointer.hoveringElement = null; } } }
private List <RaycastResult> CheckRaycasts(VRUIPointer pointer) { var raycastResult = new RaycastResult(); raycastResult.worldPosition = pointer.transform.position; raycastResult.worldNormal = pointer.transform.forward; pointer.pointerEventData.pointerCurrentRaycast = raycastResult; List <RaycastResult> raycasts = new List <RaycastResult>(); eventSystem.RaycastAll(pointer.pointerEventData, raycasts); return(raycasts); }
private void Drag(VRUIPointer pointer, List <RaycastResult> results) { pointer.pointerEventData.dragging = pointer.ButtonClick() && pointer.pointerEventData.delta != Vector2.zero; if (pointer.pointerEventData.pointerDrag) { if (pointer.pointerEventData.dragging) { if (IsHovering(pointer)) { ExecuteEvents.ExecuteHierarchy(pointer.pointerEventData.pointerDrag, pointer.pointerEventData, ExecuteEvents.dragHandler); } } else { ExecuteEvents.ExecuteHierarchy(pointer.pointerEventData.pointerDrag, pointer.pointerEventData, ExecuteEvents.dragHandler); ExecuteEvents.ExecuteHierarchy(pointer.pointerEventData.pointerDrag, pointer.pointerEventData, ExecuteEvents.endDragHandler); foreach (RaycastResult raycast in results) { ExecuteEvents.ExecuteHierarchy(raycast.gameObject, pointer.pointerEventData, ExecuteEvents.dropHandler); } pointer.pointerEventData.pointerDrag = null; } } else if (pointer.pointerEventData.dragging) { foreach (var result in results) { ExecuteEvents.ExecuteHierarchy(result.gameObject, pointer.pointerEventData, ExecuteEvents.initializePotentialDrag); ExecuteEvents.ExecuteHierarchy(result.gameObject, pointer.pointerEventData, ExecuteEvents.beginDragHandler); var target = ExecuteEvents.ExecuteHierarchy(result.gameObject, pointer.pointerEventData, ExecuteEvents.dragHandler); if (target != null) { pointer.pointerEventData.pointerDrag = target; break; } } } }
private void Click(VRUIPointer pointer, List <RaycastResult> results) { pointer.pointerEventData.eligibleForClick = pointer.ButtonClick(); if (pointer.pointerEventData.pointerPress) { if (pointer.pointerEventData.eligibleForClick) { if (!IsHovering(pointer)) { ExecuteEvents.ExecuteHierarchy(pointer.pointerEventData.pointerPress, pointer.pointerEventData, ExecuteEvents.pointerUpHandler); pointer.pointerEventData.pointerPress = null; } } else { ExecuteEvents.ExecuteHierarchy(pointer.pointerEventData.pointerPress, pointer.pointerEventData, ExecuteEvents.pointerClickHandler); ExecuteEvents.ExecuteHierarchy(pointer.pointerEventData.pointerPress, pointer.pointerEventData, ExecuteEvents.pointerUpHandler); pointer.pointerEventData.pointerPress = null; } } else if (pointer.pointerEventData.eligibleForClick) { foreach (var result in results) { var target = ExecuteEvents.ExecuteHierarchy(result.gameObject, pointer.pointerEventData, ExecuteEvents.pointerDownHandler); if (target != null) { pointer.pointerEventData.pressPosition = pointer.pointerEventData.position; pointer.pointerEventData.pointerPressRaycast = result; pointer.pointerEventData.pointerPress = target; break; } } } }
private bool NoValidCollision(VRUIPointer pointer, List <RaycastResult> results) { return(results.Count == 0 || !CheckTransformTree(results[0].gameObject.transform, pointer.pointerEventData.pointerEnter.transform)); }