private void SetPositionEventData(ref WorldPointerEventData eventData) { // get position for raycast Vector2 pointerPos = this.gestureManager.ScreenPosition; Vector3 worldPos = this.gestureManager.WorldScreenPosition; switch (this.InputType) { case StateManager.InputType.Mouse: if (this.mouseManager.IsSupported() || this.mouseManager.ShouldActivate()) { pointerPos = this.mouseManager.ScreenPosition; worldPos = this.mouseManager.WorldScreenPosition; } break; case StateManager.InputType.Joystick: if (this.joystickManager.IsSupported() || this.joystickManager.ShouldActivate()) { pointerPos = this.joystickManager.ScreenPosition; worldPos = this.joystickManager.WorldScreenPosition; } break; } // set the event position eventData.inputType = this.InputType; eventData.position = pointerPos; // screenPosition eventData.worldPosition = worldPos; // position on near plane }
public static RaycastResult GetRaycastResult(int buttonId = -1) { WorldPointerEventData data = null; if (worldPointerEventData.TryGetValue(buttonId, out data)) { return(data.pointerCurrentRaycast); } return(emptyResult); }
private void SetScrollDeltaEventData(ref WorldPointerEventData eventData) { eventData.scrollDelta = this.gestureManager.ScrollDelta; if (this.joystickManager.ShouldActivate()) { eventData.scrollDelta = this.joystickManager.ScrollDelta; } if (this.mouseManager.ShouldActivate()) { eventData.scrollDelta = this.mouseManager.ScrollDelta; } }
private bool GetWorldPointerData(int buttonId, out WorldPointerEventData data, bool create) { if (!worldPointerEventData.TryGetValue(buttonId, out data) && create) { data = new WorldPointerEventData(eventSystem) { pointerId = buttonId, }; worldPointerEventData.Add(buttonId, data); return(true); } return(false); }
private void SetDeltaEventData(ref WorldPointerEventData eventData) { eventData.useDragThreshold = false; eventData.delta = this.gestureManager.ScreenDelta; eventData.worldDelta = this.gestureManager.WorldDelta; if (this.joystickManager.ShouldActivate()) { eventData.delta = this.joystickManager.ScreenDelta; eventData.worldDelta = this.joystickManager.WorldDelta; } if (this.mouseManager.ShouldActivate()) { eventData.delta = this.mouseManager.ScreenDelta; eventData.worldDelta = this.mouseManager.WorldDelta; } }
private void SetRaycastResult(ref WorldPointerEventData eventData) { // raycast the position for any results this.eventSystem.RaycastAll(eventData, this.m_RaycastResultCache); // use first object in cache var raycast = FindFirstRaycast(this.m_RaycastResultCache); // clear the cache this.m_RaycastResultCache.Clear(); // correct raycast result if (raycast.isValid) { // for UI objects raycast.worldPosition == Vector3.zero, have to raycast the screenPosition if (raycast.worldPosition == Vector3.zero) { Ray ray = Camera.main.ScreenPointToRay(raycast.screenPosition); raycast.worldPosition = eventData.worldPosition + (ray.direction * raycast.distance); } if (raycast.worldNormal == Vector3.zero) { raycast.worldNormal = -raycast.gameObject.transform.forward; } } else { Ray ray = Camera.main.ScreenPointToRay(eventData.position); raycast.worldPosition = Camera.main.transform.position + ray.direction; raycast.worldNormal = -ray.direction; } // set the raycast data eventData.pointerCurrentRaycast = raycast; }