1

Topic: OnGetInputPosition from RawImageTouchForwarder returns Vector2.zero

I'm using Online Maps 3.10.1.1

This code is from OnlineMapsRawImageTouchForwarder:

    private Vector2 OnGetInputPosition()
    {
        if (target != image.gameObject) return Vector2.zero;
        return ProcessTouch(pointerPos, out Vector2 pos) ? pos : Vector2.zero;
    }

If target is not image.gameObject it return Vector2.zero. Target is taken from this method:

private GameObject GetTargetGameObject(Vector2 position)
{
    PointerEventData pe = new PointerEventData(EventSystem.current)
    {
        position = position
    };

    List<RaycastResult> hits = new List<RaycastResult>();
    EventSystem.current.RaycastAll(pe, hits);

    if (hits.Count == 0) return null;

    return hits[0].gameObject;
}

Meaning if we dont hit anything it returns Vector2.zero, meaning if in unity editor mouse is outside game tab and we use mouse scroll wheel map will zoom. How can I prevent that zoom? I've tried to change the OnGetInputPosition method to return Vector2.positiveInfinity, but them I'm getting exceptions "Screen position out of view frustrum" from within Online maps code on android build.

This is the UpdateZoom method which uses the OnGetInputPosition:

    protected void UpdateZoom()
    {
#if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
        return;
#else
        
        if (!HitTest()) return;

        Vector2 inputPosition = GetInputPosition();

        if (IsCursorOnUIElement(inputPosition)) return;

        if (checkScreenSizeForWheelZoom && (inputPosition.x <= 0 || inputPosition.x >= Screen.width || inputPosition.y <= 0 || inputPosition.y >= Screen.height)) return;

        float wheel = OnlineMapsInput.GetAxis("Mouse ScrollWheel");
        if (Math.Abs(wheel) < float.Epsilon) return;

#if NETFX_CORE
        wheel = -wheel;
#endif

        float delta = wheel > 0 ? zoomSpeed : -zoomSpeed;
        if (OnValidateZoom == null || OnValidateZoom(OnlineMapsZoomEvent.wheel, map.floatZoom + delta))
        {
            if (zoomMode == OnlineMapsZoomMode.target) ZoomOnPoint(delta, inputPosition);
            else map.floatZoom += delta;
        }
#endif
    }

How can I handle this? Thanks for help.

Re: OnGetInputPosition from RawImageTouchForwarder returns Vector2.zero

Hi,

Try commenting out the following line in OnlineMapsRawImageTouchForwarder.OnEnable:

control.checkScreenSizeForWheelZoom = false;

Unfortunately, since this code was written quite a long time ago, I no longer remember exactly why I disabled this option there.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.