/// <summary> /// New version of ShouldStartDrag implemented first in PointerInputModule. This version differs in that /// for ray based pointers it makes a decision about whether a drag should start based on the angular change /// the pointer has made so far, as seen from the camera. This also works when the world space ray is /// translated rather than rotated, since the beginning and end of the movement are considered as angle from /// the same point. /// </summary> private bool ShouldStartDrag(PointerEventData pointerEvent) { if (!pointerEvent.useDragThreshold) { return(true); } if (!pointerEvent.IsF3dSpacePointer()) { // Same as original behaviour for canvas based pointers return((pointerEvent.pressPosition - pointerEvent.position).sqrMagnitude >= eventSystem.pixelDragThreshold * eventSystem.pixelDragThreshold); } else { #if UNITY_ANDROID && !UNITY_EDITOR // On android allow swiping to start drag if (useSwipeScroll && ((Vector3)pointerEvent.GetSwipeStart() - Input.mousePosition).magnitude > swipeDragThreshold) { return(true); } #endif // When it's not a screen space pointer we have to look at the angle it moved rather than the pixels distance // For gaze based pointing screen-space distance moved will always be near 0 Vector3 cameraPos = pointerEvent.pressEventCamera.transform.position; Vector3 pressDir = (pointerEvent.pointerPressRaycast.worldPosition - cameraPos).normalized; Vector3 currentDir = (pointerEvent.pointerCurrentRaycast.worldPosition - cameraPos).normalized; return(Vector3.Dot(pressDir, currentDir) < Mathf.Cos(Mathf.Deg2Rad * (angleDragThreshold))); } }
public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList) { if (eventData.IsF3dSpacePointer()) { Raycast(eventData, resultAppendList, eventData.GetRay(), true); } }
public void OnPointerExit(PointerEventData eventData) { if (eventData.IsF3dSpacePointer()) { // Gaze has entered this canvas. We'll make it the active one so that canvas-mouse pointer can be used. //GCSeriesInputModule inputModule = EventSystem.current.currentInputModule as GCSeriesInputModule; //eventData.pointerEnter if (eventData.pointerPress) { //if(null == eventData.pointerEnter) //{ if (eventData.pointerPress != null) { Button uiButton = eventData.pointerPress.GetComponent <Button>(); if (null != uiButton) { uiButton.OnDeselect(eventData); } else { Toggle toggle = eventData.pointerPress.GetComponent <Toggle>(); if (toggle != null) { toggle.OnDeselect(eventData); toggle.Select(); } } Debug.Log("F3dSpaceRaycaster.OnPointerExit()"); } } //inputModule.activeGraphicRaycaster = null; } }
public void OnPointerEnter(PointerEventData eventData) { if (eventData.IsF3dSpacePointer()) { // Gaze has entered this canvas. We'll make it the active one so that canvas-mouse pointer can be used. GCSeriesInputModule inputModule = EventSystem.current.currentInputModule as GCSeriesInputModule; inputModule.activeGraphicRaycaster = this; } }
static bool IsPointerMoving(PointerEventData pointerEvent) { if (pointerEvent.IsF3dSpacePointer()) { return(true); } else { } return(pointerEvent.IsPointerMoving()); }
/// <summary> /// Exactly the same as the code from PointerInputModule, except that we call our own /// IsPointerMoving. /// /// This would also not be necessary if PointerEventData.IsPointerMoving was virtual /// </summary> /// <param name="pointerEvent"></param> protected override void ProcessDrag(PointerEventData pointerEvent) { Vector2 originalPosition = pointerEvent.position; bool moving = IsPointerMoving(pointerEvent); if (moving && pointerEvent.pointerDrag != null && !pointerEvent.dragging && ShouldStartDrag(pointerEvent)) { if (pointerEvent.IsF3dSpacePointer()) { //adjust the position used based on swiping action. Allowing the user to //drag items by swiping on the GearVR touchpad pointerEvent.position = originalPosition; } ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.beginDragHandler); pointerEvent.dragging = true; } // Drag notification if (pointerEvent.dragging && moving && pointerEvent.pointerDrag != null) { if (pointerEvent.IsF3dSpacePointer()) { pointerEvent.position = originalPosition; } // Before doing drag we should cancel any pointer down state // And clear selection! if (pointerEvent.pointerPress != pointerEvent.pointerDrag) { ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); pointerEvent.eligibleForClick = false; pointerEvent.pointerPress = null; pointerEvent.rawPointerPress = null; } ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.dragHandler); } //DeselectIfSelectionChanged(pointerEvent.pointerCurrentRaycast.gameObject, pointerEvent); }