public void RaiseSourceDown(IInputSource source, uint sourceId, InteractionSourcePressInfo pressType, object[] tags = null) { // Create input event inputEventData.Initialize(source, sourceId, tags, pressType); // Pass handler through HandleEvent to perform modal/fallback logic HandleEvent(inputEventData, OnSourceDownEventHandler); // UI events IPointingSource pointingSource; FocusManager.Instance.TryGetPointingSource(inputEventData, out pointingSource); PointerInputEventData pointerInputEventData = FocusManager.Instance.GetSpecificPointerEventData(pointingSource); if (pointerInputEventData != null && pressType == InteractionSourcePressInfo.Select) { pointerInputEventData.InputSource = source; pointerInputEventData.SourceId = sourceId; pointerInputEventData.pointerId = (int)sourceId; pointerInputEventData.eligibleForClick = true; pointerInputEventData.delta = Vector2.zero; pointerInputEventData.dragging = false; pointerInputEventData.useDragThreshold = true; pointerInputEventData.pressPosition = pointerInputEventData.position; pointerInputEventData.pointerPressRaycast = pointerInputEventData.pointerCurrentRaycast; ExecuteEvents.ExecuteHierarchy(inputEventData.selectedObject, pointerInputEventData, ExecuteEvents.pointerDownHandler); } }
public void RaiseSourceUp(IInputSource source, uint sourceId, InteractionSourcePressInfo pressType, object[] tags = null) { // Create input event inputEventData.Initialize(source, sourceId, tags, pressType); // Pass handler through HandleEvent to perform modal/fallback logic HandleEvent(inputEventData, OnSourceUpEventHandler); // UI events IPointingSource pointingSource; FocusManager.Instance.TryGetPointingSource(inputEventData, out pointingSource); PointerInputEventData pointerInputEventData = FocusManager.Instance.GetSpecificPointerEventData(pointingSource); if (pointerInputEventData != null && pressType == InteractionSourcePressInfo.Select) { pointerInputEventData.InputSource = source; pointerInputEventData.SourceId = sourceId; if (pointerInputEventData.selectedObject != null) { ExecuteEvents.ExecuteHierarchy(pointerInputEventData.selectedObject, pointerInputEventData, ExecuteEvents.pointerUpHandler); ExecuteEvents.ExecuteHierarchy(pointerInputEventData.selectedObject, pointerInputEventData, ExecuteEvents.pointerClickHandler); } pointerInputEventData.Clear(); } }
public void RaiseSourceDown(IInputSource source, uint sourceId, InteractionSourcePressInfo pressType, object[] tags = null) { // Create input event inputEventData.Initialize(source, sourceId, tags, pressType); // Pass handler through HandleEvent to perform modal/fallback logic HandleEvent(inputEventData, OnSourceDownEventHandler); // UI events if (ShouldSendUnityUiEvents && pressType == InteractionSourcePressInfo.Select) { PointerInputEventData pointerInputEventData = FocusManager.Instance.GetPointerEventData(); pointerInputEventData.InputSource = source; pointerInputEventData.SourceId = sourceId; pointerInputEventData.eligibleForClick = true; pointerInputEventData.delta = Vector2.zero; pointerInputEventData.dragging = false; pointerInputEventData.useDragThreshold = true; pointerInputEventData.pressPosition = pointerInputEventData.position; pointerInputEventData.pointerPressRaycast = pointerInputEventData.pointerCurrentRaycast; HandleEvent(pointerInputEventData, ExecuteEvents.pointerDownHandler); } }
/// <summary> /// Raise the event OnFocusExit to the game object when focus exists it. /// </summary> /// <param name="deFocusedObject"></param> public void RaiseFocusExit(GameObject deFocusedObject) { ExecuteEvents.ExecuteHierarchy(deFocusedObject, null, OnFocusExitEventHandler); if (ShouldSendUnityUiEvents) { PointerInputEventData pointerInputEventData = FocusManager.Instance.GetPointerEventData(); ExecuteEvents.ExecuteHierarchy(deFocusedObject, pointerInputEventData, ExecuteEvents.pointerExitHandler); } }
public GameObject TryGetFocusedObject(BaseEventData eventData) { IPointingSource pointingSource; TryGetPointingSource(eventData, out pointingSource); PointerInputEventData pointerInputEventData = GetSpecificPointerEventData(pointingSource); Debug.Assert(pointerInputEventData != null); return(pointerInputEventData.selectedObject); }
/// <summary> /// Raise the event OnFocusExit to the game object when focus exists it. /// </summary> /// <param name="deFocusedObject">The object that is deFocused.</param> public void RaiseFocusExit(GameObject deFocusedObject) { ExecuteEvents.ExecuteHierarchy(deFocusedObject, null, OnFocusExitEventHandler); PointerInputEventData pointerInputEventData = FocusManager.Instance.GetGazePointerEventData(); if (pointerInputEventData != null) { ExecuteEvents.ExecuteHierarchy(deFocusedObject, pointerInputEventData, ExecuteEvents.pointerExitHandler); } }
public PointerInputEventData GetPointerEventData() { if (UnityUIPointerEvent == null) { UnityUIPointerEvent = new PointerInputEventData(EventSystem.current); } else { UnityUIPointerEvent.Clear(); } return(UnityUIPointerEvent); }
public PointerInputEventData BorrowPointerEventData() { if (uiRaycastPointerInputData == null) { uiRaycastPointerInputData = new PointerInputEventData(EventSystem.current); } else { Clear(uiRaycastPointerInputData); } return(uiRaycastPointerInputData); }
public GameObject TryGetFocusedObject(BaseEventData eventData) { IPointingSource pointingSource; TryGetPointingSource(eventData, out pointingSource); PointerInputEventData pointerInputEventData = GetSpecificPointerEventData(pointingSource); // GetSpecificPointerEventData can return null. Be sure to handle that case. if (pointerInputEventData == null) { return(null); } return(pointerInputEventData.selectedObject); }
public GameObject TryGetFocusedObject(BaseEventData eventData) { FocusDetails?details = TryGetFocusDetails(eventData); if (details == null) { return(null); } IPointingSource pointingSource; TryGetPointingSource(eventData, out pointingSource); PointerInputEventData pointerInputEventData = GetSpecificPointerEventData(pointingSource); pointerInputEventData.selectedObject = details.Value.Object; return(details.Value.Object); }
public void RaiseSourceUp(IInputSource source, uint sourceId, InteractionSourcePressInfo pressType, object[] tags = null) { // Create input event inputEventData.Initialize(source, sourceId, tags, pressType); // Pass handler through HandleEvent to perform modal/fallback logic HandleEvent(inputEventData, OnSourceUpEventHandler); // UI events if (ShouldSendUnityUiEvents && pressType == InteractionSourcePressInfo.Select) { PointerInputEventData pointerInputEventData = FocusManager.Instance.GetPointerEventData(); pointerInputEventData.InputSource = source; pointerInputEventData.SourceId = sourceId; HandleEvent(pointerInputEventData, ExecuteEvents.pointerUpHandler); HandleEvent(pointerInputEventData, ExecuteEvents.pointerClickHandler); } }
private void UpdatePointing(PointerData pointer) { pointer.PointingSource.UpdatePointer(); Ray pointingRay = pointer.PointingSource.Ray; float extent = GetPointingExtent(pointer); IList <LayerMask> prioritizedLayerMasks = (pointer.PointingSource.PrioritizedLayerMasksOverride ?? pointingPrioritizedLayerMasks); LayerMask combinedLayerMasks = GetCombinedLayerMask(prioritizedLayerMasks); RaycastHit? physicsHit; RaycastResult?uiHit; if (prioritizedLayerMasks.Count > 1) { RaycastHit[] hits = Physics.RaycastAll(pointingRay, extent, combinedLayerMasks); physicsHit = TryGetPreferredHit(hits, prioritizedLayerMasks); } else { RaycastHit hit; physicsHit = Physics.Raycast(pointingRay, out hit, extent, combinedLayerMasks) ? (RaycastHit?)hit : null; } if ((pointableCanvases.Count == 0) || (EventSystem.current == null)) { uiHit = null; } else { if (uiRaycastCamera == null) { uiRaycastCamera = new GameObject("UI Raycast Camera").AddComponent <Camera>(); uiRaycastCamera.transform.parent = transform; // Make sure the raycast starts as close the the camera as possible. Ideally, this would // be 0, but as of Unity 5.5, setting it to 0 causes the raycast to complain that the // screen point isn't in the camera's view frustum. uiRaycastCamera.nearClipPlane = 0.01f; // Make sure the camera's pixel rect is large enough for raycasting to work as desired. As // of Unity 5.5, setting it much smaller than this makes the raycast miss things. uiRaycastCamera.pixelRect = new Rect(0, 0, 100, 100); // Don't waste performance rendering anything. uiRaycastCamera.enabled = false; foreach (Canvas canvas in pointableCanvases) { canvas.worldCamera = uiRaycastCamera; } if (uiRaycastPointerInputData == null) { uiRaycastPointerInputData = new PointerInputEventData(EventSystem.current); } Debug.Assert(uiRaycastResults == null); uiRaycastResults = new List <RaycastResult>(); } Debug.Assert(uiRaycastCamera != null); Debug.Assert(uiRaycastPointerInputData != null); Debug.Assert(uiRaycastResults != null); foreach (Canvas canvas in pointableCanvases) { Debug.Assert(canvas.worldCamera == uiRaycastCamera); } uiRaycastCamera.transform.position = pointingRay.origin; uiRaycastCamera.transform.forward = pointingRay.direction; Clear(uiRaycastPointerInputData); uiRaycastPointerInputData.position = new Vector2((uiRaycastCamera.pixelWidth / 2), (uiRaycastCamera.pixelHeight / 2)); uiRaycastResults.Clear(); EventSystem.current.RaycastAll(uiRaycastPointerInputData, uiRaycastResults); uiHit = TryGetPreferredHit(uiRaycastResults, prioritizedLayerMasks); if (uiHit != null) { RaycastResult patchedUiHit = uiHit.Value; float totalDistance = (patchedUiHit.distance + uiRaycastCamera.nearClipPlane); patchedUiHit.distance = totalDistance; Debug.Assert((patchedUiHit.worldPosition == Vector3.zero), "As of Unity 5.5, UI Raycasts always" + " return worldPosition (0,0,0), so we'll fill it in here with the correct value. If this" + " assertion fires, see what data is available, and consider using it instead of our fill in." ); patchedUiHit.worldPosition = (pointingRay.origin + (totalDistance * pointingRay.direction)); Debug.Assert((patchedUiHit.worldNormal == Vector3.zero), "As of Unity 5.5, UI Raycasts always" + " return worldNormal (0,0,0), so we'll fill it in here with something incorrect, but" + " reasonable. If this assertion fires, see what data is available, and consider using it" + " instead of our fill in." ); patchedUiHit.worldNormal = (-pointingRay.direction); uiHit = patchedUiHit; } } if ((physicsHit != null) && (uiHit != null)) { for (int iMask = 0; iMask < prioritizedLayerMasks.Count; iMask++) { LayerMask mask = prioritizedLayerMasks[iMask]; bool physicsIsInMask = physicsHit.Value.transform.gameObject.IsInLayerMask(mask); bool uiIsInMask = uiHit.Value.gameObject.IsInLayerMask(mask); if (physicsIsInMask && uiIsInMask) { // In the case of tie in priority and distance, we give preference to the UI, // assuming that if people stick UI on top of 3D objects, they probably want // the UI to take the pointer. if (uiHit.Value.distance <= physicsHit.Value.distance) { pointer.UpdateHit(uiHit.Value); break; } else { pointer.UpdateHit(physicsHit.Value); break; } } else if (physicsIsInMask) { pointer.UpdateHit(physicsHit.Value); break; } else if (uiIsInMask) { pointer.UpdateHit(uiHit.Value); break; } else { // Nothing... keep searching for a mask that contains at least one of the hits. } } Debug.Assert(pointer.End.Object != null); } else if (physicsHit != null) { pointer.UpdateHit(physicsHit.Value); } else if (uiHit != null) { pointer.UpdateHit(uiHit.Value); } else { pointer.UpdateHit(extent); } }