Author Topic: UICamera.currentScheme changes to Mouse unexpectedly  (Read 3457 times)

titan_artix

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 6
    • View Profile
UICamera.currentScheme changes to Mouse unexpectedly
« on: September 29, 2017, 02:34:42 PM »
We recently upgraded our project from 3.10.2 to 3.11.4.

Our game runs on Android and iOS handheld devices as well as on PC and Mac via Steam.

After completing the NGUI upgrade process and releasing our game update, we received several report that our mobile interface on Android and iOS would convert incorrectly and show our PC interface. We have logic in place that detects user input and displays the appropriate interface accordingly.  In fact we have even supported devices like a Surface tablet where the user could be using touch, then attach a keyboard and mouse and successfully continue playing with the correct PC interface.

Suddenly now after the 3.11.4 update, we're seeing our intended behavior is not working correctly.  After some testing, we've detected that the UICamera.currentScheme property returns Mouse incorrectly when exclusively using Touch only.  We tested this on a Nexus 7 and Google Pixel and both would find that the currentScheme would switch to Mouse on every alternate touch. This could then lead to an unintended UI change on our end when our logic looks to currentScheme to determine the layout.

You could see how a check like this would fail if the currentScheme value was no longer Touch.
  1. if (UICamera.currentScheme == UICamera.ControlScheme.Touch)
  2.      ControlScheme = ControlScheme.HANDHELD;
  3. else
  4.      ControlScheme = ControlScheme.PC;
  5.  

I tracked this down further and found that the switch to Mouse seems to originate in the ProcessMouse() function of the UICamera class around line 2157, when the sqrMag value check doesn't return. Instead logic proceeds and the currentKey is set to KeyCode.Mouse0.  This seems to then convert the Scheme to Mouse shortly afterward and everything gets messed up.

In NGUI's previous version this switch to Mouse doesn't occur.  We tried to diff the code to figure out what's up, but haven't quite been able to pinpoint the issue.  Any help here would be great.

We haven't made any other changes that would affect this logic and we've been using all of the Event Sources below successfully for a long while now.


titan_artix

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: UICamera.currentScheme changes to Mouse unexpectedly
« Reply #1 on: October 04, 2017, 08:58:50 AM »
After messing around with this for a while more, I found that changing the line of code below seems to prevent the unintended scheme switch from Touch to Mouse and things work on both Touch devices and Keyboard / Mouse setups as expected.  I'm not sure what other consequences changing this line has yet as we haven't tested it extensively, but so far this tweak seems to prevent Touch inputs from being interpreted as Mouse input:

In UICamera.cs, I changed this around line 2130:
  1. if (currentScheme == ControlScheme.Touch && activeTouches.Count > 0) return;

To this:
  1. if (currentScheme == ControlScheme.Touch) return;

We definitely need more testing to determine why this works and I doubt tweaking this line is a good thing as there are probably other unintended consequences.  Any ideas why this change would fix things? I haven't been able to pinpoint what's going on, even after performing a full file diff between versions.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamera.currentScheme changes to Mouse unexpectedly
« Reply #2 on: October 07, 2017, 06:21:50 AM »
In your case you are effectively disabling mouse input -- which you should really do in inspector. Simply turn off the mouse input checkbox.

The device is reporting a mouse position, so the input gets switched to it. Turning off mouse input on the mobile device should resolve the problem.

titan_artix

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: UICamera.currentScheme changes to Mouse unexpectedly
« Reply #3 on: October 10, 2017, 02:20:29 PM »
Hey thanks for the response,

We're specifically trying to support devices like the Surface tablet where the user might be playing with Touch and then decide to dock the tablet at their desk with a keyboard and mouse and continue playing.  Our game logic supports this setup and things worked for us in the previous version of NGUI.  For a long while now we've checked 'Mouse', 'Touch' and 'Keyboard' as our Event sources (shown in screenshot)

Since we updated to 3.11.4, this behavior no longer works. Now even while exclusively using touch only on a tablet like a Nexus 7, the system switches over to Mouse on alternative touches. Any help here would be great.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamera.currentScheme changes to Mouse unexpectedly
« Reply #4 on: October 19, 2017, 02:10:36 AM »
Have you tried doing a diff on he UICamera.cs file between the two versions to track down the cause? UICamera.currentScheme was changed from:
  1.                 get
  2.                 {
  3.                         if (mCurrentKey == KeyCode.None) return ControlScheme.Touch;
  4.                         if (mCurrentKey >= KeyCode.JoystickButton0) return ControlScheme.Controller;
  5.                         if (current != null && mLastScheme == ControlScheme.Controller &&
  6.                                 (mCurrentKey == current.submitKey0 || mCurrentKey == current.submitKey1))
  7.                                 return ControlScheme.Controller;
  8.                         return ControlScheme.Mouse;
  9.                 }
to:
  1.                 get
  2.                 {
  3.                         if (mCurrentKey == KeyCode.None) return ControlScheme.Touch;
  4.                         if (mCurrentKey >= KeyCode.JoystickButton0) return ControlScheme.Controller;
  5.                        
  6.                         if (current != null)
  7.                         {
  8.                                 if (mLastScheme == ControlScheme.Controller && (mCurrentKey == current.submitKey0 || mCurrentKey == current.submitKey1))
  9.                                         return ControlScheme.Controller;
  10.  
  11.                                 if (current.useMouse) return ControlScheme.Mouse;
  12.                                 if (current.useTouch) return ControlScheme.Touch;
  13.                                 return ControlScheme.Controller;
  14.                         }
  15.                         return ControlScheme.Mouse;
  16.                 }
That's about it that I can see that is related to events. UICamera class is the only one you need to look at since that's where the events happen.