Author Topic: Mouse keeps resetting back to 0,0;  (Read 5459 times)

Pendulum

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Mouse keeps resetting back to 0,0;
« on: August 13, 2015, 11:29:33 PM »
I'm using the 2D Engine at the moment as as soon as I add a NGUI 2D (or 3D) UI and enter the game the mouse cursor keeps flicking to the center of the screen over and over. I remove the UI and it goes back to normal. I can't figure out what I'm doing wrong.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Mouse keeps resetting back to 0,0;
« Reply #1 on: August 14, 2015, 09:32:53 AM »
Because you have a joystick plugged in that's reporting non-zero values.

Either unplug the joystick, disable controller input on UICamera, or turn off "Auto Hide Cursor" on UICamera (if you have the Pro version of NGUI).

SkobbejakGames

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Mouse keeps resetting back to 0,0;
« Reply #2 on: August 16, 2015, 09:13:02 AM »
@ArenMook: I keep getting this as well but only when Im trying to use a controler to control the menu, Ive been trying to get a Controler to work with my menu for the past 24 hours now and nothing seems to actually work, I can see that the defined Axis and buttons get detected but the only thing they do is set the cursor back to 0,0 they dont actually navigate, pan or select buttons like they should.

I am using Rewired and followed these 2 threads on creating a script to integrate Rewired with NGUI:

http://www.tasharen.com/forum/index.php?topic=13171
http://www.tasharen.com/forum/index.php?topic=13047.0

I am using a modified version of the script you made to integrate inControl with NGUI:

  1. using UnityEngine;
  2. using Rewired;
  3.  
  4. public class RewiredNGUI : MonoBehaviour
  5. {
  6.         void OnEnable ()
  7.         {
  8.                 UICamera.GetKey = GetKey;
  9.                 UICamera.GetKeyDown = GetKeyDown;
  10.                 UICamera.GetKeyUp = GetKeyUp;
  11.                 UICamera.GetAxis = GetAxis;
  12.         }
  13.        
  14.         static bool GetKeyDown (KeyCode key)
  15.         {
  16.                 if (key >= KeyCode.JoystickButton0)
  17.                 {      
  18.                         switch (key)
  19.                         {
  20.                         case KeyCode.JoystickButton0: return ReInput.players.GetPlayer(0).GetButtonDown(25);
  21.                         case KeyCode.JoystickButton1: return ReInput.players.GetPlayer(0).GetButtonDown(25);
  22.                         case KeyCode.JoystickButton2: return ReInput.players.GetPlayer(0).GetButtonDown(25);
  23.                         case KeyCode.JoystickButton3: return ReInput.players.GetPlayer(0).GetButtonDown(25);
  24.                         case KeyCode.JoystickButton4: return ReInput.players.GetPlayer(0).GetButtonDown(25);
  25.                         case KeyCode.JoystickButton5: return ReInput.players.GetPlayer(0).GetButtonDown(25);
  26.                         case KeyCode.JoystickButton6: return ReInput.players.GetPlayer(0).GetButtonDown(25);
  27.                         case KeyCode.JoystickButton7: return ReInput.players.GetPlayer(0).GetButtonDown(25);
  28.                         case KeyCode.JoystickButton8: return ReInput.players.GetPlayer(0).GetButtonDown(25);
  29.                         case KeyCode.JoystickButton9: return ReInput.players.GetPlayer(0).GetButtonDown(25);
  30.                         }
  31.                 }
  32.                 return Input.GetKeyDown(key);
  33.         }
  34.        
  35.         static bool GetKey (KeyCode key)
  36.         {
  37.                 if (key >= KeyCode.JoystickButton0)
  38.                 {      
  39.                         switch (key)
  40.                         {
  41.                         case KeyCode.JoystickButton0: return ReInput.players.GetPlayer(0).GetButton(25);
  42.                         case KeyCode.JoystickButton1: return ReInput.players.GetPlayer(0).GetButton(25);
  43.                         case KeyCode.JoystickButton2: return ReInput.players.GetPlayer(0).GetButton(25);
  44.                         case KeyCode.JoystickButton3: return ReInput.players.GetPlayer(0).GetButton(25);
  45.                         case KeyCode.JoystickButton4: return ReInput.players.GetPlayer(0).GetButton(25);
  46.                         case KeyCode.JoystickButton5: return ReInput.players.GetPlayer(0).GetButton(25);
  47.                         case KeyCode.JoystickButton6: return ReInput.players.GetPlayer(0).GetButton(25);
  48.                         case KeyCode.JoystickButton7: return ReInput.players.GetPlayer(0).GetButton(25);
  49.                         case KeyCode.JoystickButton8: return ReInput.players.GetPlayer(0).GetButton(25);
  50.                         case KeyCode.JoystickButton9: return ReInput.players.GetPlayer(0).GetButton(25);
  51.                         }
  52.                 }
  53.                 return Input.GetKey(key);
  54.         }
  55.        
  56.         static bool GetKeyUp (KeyCode key)
  57.         {
  58.                 if (key >= KeyCode.JoystickButton0)
  59.                 {      
  60.                         switch (key)
  61.                         {
  62.                         case KeyCode.JoystickButton0: return ReInput.players.GetPlayer(0).GetButtonUp(25);
  63.                         case KeyCode.JoystickButton1: return ReInput.players.GetPlayer(0).GetButtonUp(25);
  64.                         case KeyCode.JoystickButton2: return ReInput.players.GetPlayer(0).GetButtonUp(25);
  65.                         case KeyCode.JoystickButton3: return ReInput.players.GetPlayer(0).GetButtonUp(25);
  66.                         case KeyCode.JoystickButton4: return ReInput.players.GetPlayer(0).GetButtonUp(25);
  67.                         case KeyCode.JoystickButton5: return ReInput.players.GetPlayer(0).GetButtonUp(25);
  68.                         case KeyCode.JoystickButton6: return ReInput.players.GetPlayer(0).GetButtonUp(25);
  69.                         case KeyCode.JoystickButton7: return ReInput.players.GetPlayer(0).GetButtonUp(25);
  70.                         case KeyCode.JoystickButton8: return ReInput.players.GetPlayer(0).GetButtonUp(25);
  71.                         case KeyCode.JoystickButton9: return ReInput.players.GetPlayer(0).GetButtonUp(25);
  72.                         }
  73.                 }
  74.                 return Input.GetKeyUp(key);
  75.         }
  76.        
  77.         static float GetAxis (string name)
  78.         {
  79.                 switch (name)
  80.                 {
  81.                 case "Horizontal": return ReInput.players.GetPlayer(0).GetAxis(23); // Match UICamera.horizontalAxisName
  82.                 case "Vertical": return ReInput.players.GetPlayer(0).GetAxis(24); // Match UICamera.verticalAxisName
  83.                 case "PX": return ReInput.players.GetPlayer(0).GetAxis(23); // Match UICamera.horizontalAxisName
  84.                 case "PY": return ReInput.players.GetPlayer(0).GetAxis(24); // Match UICamera.verticalAxisName
  85.                 }
  86.                 return Input.GetAxis(name);
  87.         }
  88. }

I have also tried disabling and enabling the different input types on the UICamera script as well as enabling and disabling the "Auto Hide Cursor" function and nothing seems to help. I am running the latest version of NGUI on Unity 5.1.2 (Windows 7 64bit).

I can confirm that it is indeed a problem with NGUI as Rewired works fine with UFPS and all my gameplay controls work, I can also use the controller fine on Rewired's in-game Control Mapper tool which is built using Unity 4.6+ UI system and seeing as NGUI is detecting the inputs but just not mapping the correct functions and sending the cursor to 0,0 leads me to think that it is definitely some kind of conlict with NGUI.

Please any help on the matter would be immensely appreciated, as I need to get controller support sorted out as fast as possible and it has already eaten up so much of my time.

SkobbejakGames

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Mouse keeps resetting back to 0,0;
« Reply #3 on: August 16, 2015, 04:13:39 PM »
Managed to get it to work, I didnt know about the UIKeyNavigation component after I set that up on all the necessary elements everything is working now.

The only thing that Im still stuggling with is ScrollViews, I can access the toggles and Sliders within my ScrollView, but the ScrollView and ScrollBar doesnt move down or up.

SkobbejakGames

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Mouse keeps resetting back to 0,0;
« Reply #4 on: August 16, 2015, 06:51:03 PM »
Ok, awesome managed to get the ScrollView to scroll nicely now, I just attached a UICenterOnChild Behaviour to the ScrollView object and then I created a Modified version of the UICenterOnClick Behaviour that follows OnHover instead, then I just placed the newly created UICenterOnHover script on all the child elements and voila.

Just one problem that I am still sitting with though, for some reason PopUpLists wont close when I select any of the options withing it, it seems like it is selecting as it flickers when I press the confirm button but the PopUp just stays open and doesnt want to close. Again if anyone could perhaps help on the matter it would be immensely appreciated.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Mouse keeps resetting back to 0,0;
« Reply #5 on: August 18, 2015, 04:52:36 PM »
The selection of popup lists is done via the submit buttons specified on the UICamera. That's about all I can say. I am not sure why it would flicker for you. Perhaps you have it set to open on a key up event instead of a click.