Topic: Map Input only when Mouse over Map

Hi there,

is there a built-in way to limit user control over the map to when the cursor is actually over the map? I am sure I can program this myself but I thought maybe it's already there somewhere hidden.

I am using the GUI setup with "Map Image" where a Map Render Texture is drawn. The Map Image is positioned on the screen such as a draggable window in Windows. I can move/scroll the map even if the mouse cursor is outside of this window area.

Thanks for your help!

Re: Map Input only when Mouse over Map

Hello.

As far as I understand you are using Raw Image Touch Forwarder, right?!
If so, this behavior has already been fixed.
Email me (support@infinity-code.com) and I will send you a modified script.

If not, please explain in detail the structure of your application (I am interested in how and where the map is used).
Quite possibly, a small video will help a lot here.

Kind Regards,
Infinity Code Team.

uContext is Editor PowerPack (more than 50 tools) that take your workflow in Unity Editor to a next level, simplifies working with content, adds new features, corrects and improves the editor’s built-in behaviors. Click here to download uContext Basic for free.

Re: Map Input only when Mouse over Map

Thanks, sent you a mail!

Quick follow-up question:
I want to change drag control from Mouse 0 to Mouse 1 to keep Mouse 0 free for other tasks such as selection of elements on the map. How would I modify the code for that?

Am I right that this is only possible by modifying the code at OnlineMapsTouchForwarder in OnGetTouchCount() from GetMouseButton(0) to GetMouseButton(1)? Because this part of the code is embedded in #if UNITY_EDITOR markers. I also found GetTouchCount() in OnlineMapsControlBase. Is this the standalone counterpart?

Thanks!

Re: Map Input only when Mouse over Map

Yes, you are thinking in the right direction.
This must be done using OnGetTouchCount and GetMouseButton(1).

GetMouseButton also is present in #else.

Kind Regards,
Infinity Code Team.

uContext is Editor PowerPack (more than 50 tools) that take your workflow in Unity Editor to a next level, simplifies working with content, adds new features, corrects and improves the editor’s built-in behaviors. Click here to download uContext Basic for free.

Re: Map Input only when Mouse over Map

Thanks, this worked perfectly. Now, I can drag the map with the right mouse button to avoid faulty user input. This is because I want to have some UI functions, where you need to hold left mouse and move the cursor around to "paint" on the map. So, to unify user control, I also want clicking on markers to be still triggered by left mouse.

Unfortunately, when changing the button for dragging the map to right mosue, clicking on markers suddenly also only works with right click and not left click anymore. I looked into it and understand why that is (OnlineMapsControlbase / OnMapRelease). What would be the best approach to change this. I kind of understand what is going on but it's too much code to really make that decision.

Re: Map Input only when Mouse over Map

Unfortunately I didn't understand your problem.
When you intercept OnGetTouchCount it automatically works for map and markers.
Here's a short video about it:
https://www.dropbox.com/s/qm5fl69sjw6qf … 0.mp4?dl=0
Left-clicking - red circle, right-clicking - blue circle.

Kind Regards,
Infinity Code Team.

uContext is Editor PowerPack (more than 50 tools) that take your workflow in Unity Editor to a next level, simplifies working with content, adds new features, corrects and improves the editor’s built-in behaviors. Click here to download uContext Basic for free.

Re: Map Input only when Mouse over Map

Thank you very much for the video. Yes, this is exactly what I mean.

If you set "return Input.GetMouseButton(1) ? 1 : 0;"
-> Map dragging: Right Mouse
-> Marker OnPress event: Right Mouse

If you set "return Input.GetMouseButton(0) ? 1 : 0;"
-> Map dragging: Left Mouse
-> Marker OnPress event: Left Mouse

What I want:
-> Map dragging: Right Mouse
-> Marker OnPress event: Left Mouse

Those are the only events I think I can use:
OnClick
OnDoubleClick
OnPress
OnLongClick

What I would need:
OnClickRight

I just thought maybe I am missing something. Since your scripts are intertangled with each other heavily - plus, I can not easily raycast the markers through the raw image -, I just thought I ask before trying to change the scripts by myself.

Re: Map Input only when Mouse over Map

Something like this (OnlineMapsRawImageTouchForwarder.OnGetTouchCount):

    private int OnGetTouchCount()
    {
        if (target != image.gameObject) return 0;

        int button = 1;
        Vector2 screenPosition = map.control.GetInputPosition();
        IOnlineMapsInteractiveElement interactiveElement = map.control.GetInteractiveElement(screenPosition);
        if (interactiveElement != null)
        {
            button = 0;
        }

#if UNITY_EDITOR
        return Input.GetMouseButton(button) ? 1 : 0;
#else
        if (Input.touchSupported)
        {
            if (Input.touchCount > 0) return Input.touchCount;
        }
        return Input.GetMouseButton(button) ? 1 : 0;
#endif
    }
Kind Regards,
Infinity Code Team.

uContext is Editor PowerPack (more than 50 tools) that take your workflow in Unity Editor to a next level, simplifies working with content, adds new features, corrects and improves the editor’s built-in behaviors. Click here to download uContext Basic for free.