1 (edited by stephen 2016-03-16 07:10:09)

Topic: Android/Samsung Tablet: NGUI Texture, first touch not firing events

Unity 5.3.2f1, Online Maps latest stable
Android Build, Samsung  SM-P900 Table (Note 2)
Online Maps NGUI Texture Control, no additional components
Build Symbol Defines: CROSS_PLATFORM_INPUT;NGUI
--same issue with both MOBILE_INPUT defined, and not defined

Additional Info:
Allow Add Marker : OFF
Allow Zoom: ON
Allow User Control: ON
Invert Touch Zoom: OFF
Zoom In On Double Click: OFF

I was testing an Android build/deploy of my app, and discovered that I could not drag the map, but I could pinch-zoom (so input events in general are working). Build was generated using BUILD AND RUN of the Android target to a USB connected device.

I could press my markers as expected, as well as other NGUI objects, so press events in general are working.

Further troubleshooting using Unity Remote 4, Unity Editor and Debug.log to catch events, I determined that at least two events were not firing during user input on the map:

OnlineMapsControlBase.instance.OnMapPress += OnMapPress; <-- would not fire
OnlineMapsControlBase.instance.OnMapDrag += OnMapDrag; <-- would not fire
OnlineMapsControlBase.instance.OnMapRelease += OnMapRelease; <-- fired as expected

I used the following to test the events firing/not firing:

public class OverlandMap : MonoBehaviour {

    void OnMapPress()
    {
        Debug.Log("OverlandMap--onMapPress fired");
    }

    void OnMapRelease()
    {
        Debug.Log("OverlandMap--onMapRelease fired");
    }

    void OnMapDrag()
    {
        Debug.Log("OverlandMap--onMapDrag fired");
    }
    // Use this for initialization
    void Start () {
        OnlineMapsControlBase.instance.OnMapPress += OnMapPress;
        OnlineMapsControlBase.instance.OnMapRelease += OnMapRelease;
        OnlineMapsControlBase.instance.OnMapDrag += OnMapDrag;
   }
}

By random chance, I clicked on the Unity Editor Game window while the build was still running, and saw the OnMapPress event fire in my Console. I then went back to my tablet, and all events were working as normal--they fired in the Console window, and the map scrolled normally (via drag gesture). This is reproduceable--it happens every run.

Obviously I can't click on the game window when running an app native build (outside of Unity Remote/Unity Editor), but I'm pretty sure the same will happen.

To make sure it wasn't my error somewhere, I then used a basic project with a simple NGUI Texture map and was able to duplicate.

I did try some troubleshooting with VS 2015 attached as debugger, and confirmed that OnlineMapsControlBase::OnMapBasePress() was being called, but quickly got lost in the camera/map event processing code.

Please let me know if you need any additional information or troubleshooting assistance.

2 (edited by stephen 2016-03-16 16:23:44)

Re: Android/Samsung Tablet: NGUI Texture, first touch not firing events

Found the problem:

OnlineMapsControlBase.cs:

    protected void OnMapBasePress()
    {
        if (waitZeroTouches)
        {
            if (Input.touchCount <= 1) waitZeroTouches = false;
            else return;
        }

        dragMarker = null;
        if (!HitTest()) return;  // test to see if map is under the interaction point

OnlineMapsNGUITextureControl.cs:

    protected override bool HitTest()
    {
        return UICamera.hoveredObject == gameObject; 
        // assumes mouse pointer is hovering over map object...but no mouse pointer on tablets
    }

UICamera.hoveredObject is always null on my tablet (no concept of hovering I assume since there is no mouse cursor).

Once you click on the Game Window (under Unity Remote), UICamera.hoveredObject becomes the map object (and never changes), so the if (!HitTest()) return; call starts succeeding, and the rest of the events are processed.

I'm guessing we need to do an #ifdef for mobile devices, and have an alternate test for clicking on the map?

Re: Android/Samsung Tablet: NGUI Texture, first touch not firing events

Hello.

Yes, I too have found this line.
Use compilation directive is a possible solution.
But I want to understand why this is happening.
We do not use it correctly, or is it a bug in NGUI.

NGUI API Reference:

/// <summary>
/// The object over which the mouse is hovering over, or the object currently selected by the controller input.
/// Mouse and controller input share the same hovered object, while touches have no hovered object at all.
/// Checking this value from within a touch-based event will simply return the current touched object.
/// </summary>

static public GameObject hoveredObject
Kind Regards,
Infinity Code Team.

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

Re: Android/Samsung Tablet: NGUI Texture, first touch not firing events

It does sound like a bug on their side, I'd agree.

It's also possible I have an unusual set of defines...as you know I'm still new to Unity in general, and this is my first Android build attempt...I didn't myself add anything except NGUI to the Symbol defines--Unity did the rest...but is it the right set of defines?

Build Settings -> Player Settings -> Scripting Define Symbols: CROSS_PLATFORM_INPUT;MOBILE_INPUT;NGUI

Re: Android/Samsung Tablet: NGUI Texture, first touch not firing events

I do not know what is «CROSS PLATFORM INPUT» and «MOBILE_INPUT».
This is from some third-party asset?
Online Maps and NGUI not require those directives.

Kind Regards,
Infinity Code Team.

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

Re: Android/Samsung Tablet: NGUI Texture, first touch not firing events

I found a way to fix it.

OnlineMapsNGUITextureControl.cs

    protected override bool HitTest()
    {
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
        return UICamera.currentTouch != null && UICamera.currentTouch.current == gameObject;
#else
        return UICamera.hoveredObject == gameObject;
#endif
    }
Kind Regards,
Infinity Code Team.

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

Re: Android/Samsung Tablet: NGUI Texture, first touch not firing events

Alex Vertax wrote:

I do not know what is «CROSS PLATFORM INPUT» and «MOBILE_INPUT».
This is from some third-party asset?
Online Maps and NGUI not require those directives.

They were added to the Build Settings by Unity when I selected the Android build target.

CROSS_PLATFORM_INPUT I think is something new with Unity 5...not sure where MOBILE_INPUT came from myself.

Re: Android/Samsung Tablet: NGUI Texture, first touch not firing events

Alex Vertax wrote:

I found a way to fix it.

OnlineMapsNGUITextureControl.cs

    protected override bool HitTest()
    {
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
        return UICamera.currentTouch != null && UICamera.currentTouch.current == gameObject;
#else
        return UICamera.hoveredObject == gameObject;
#endif
    }

Looks good, thanks!

Re: Android/Samsung Tablet: NGUI Texture, first touch not firing events

Confirmed the new code works perfectly on an Android build deployed to my tablet.

When run through the editor using Unity Remote to connect to the tablet, it does the same thing as before--you can't drag the map until you manually click on the map once in the Unity Editor Game window (as expected with the code as it stands).

For testing purposes  in my build I'm going to make it just

#if (UNITY_ANDROID || UNITY_IOS)

for now, since Unity Remote is a pretty useful testing tool for me.

Thanks much for the confirmation and fix!