Author Topic: UICamera Use Keyboard problem  (Read 4959 times)

trollg

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
UICamera Use Keyboard problem
« on: May 20, 2014, 10:14:40 AM »
Hi

I am developing a 3d platformer game and I use ngui. When the player runs by using the arrow and wasd buttons with the standard input method, if the pause menu gets enabled without stop pressing the button, the UIButtons inside the panel get automatically selected one after the other even when the input key is not pressed.
I have UICamera use keyboard on and UIButtonKeys script on my buttons.

How can I stop that?
Thanx

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamera Use Keyboard problem
« Reply #1 on: May 20, 2014, 02:24:57 PM »
Your UI responds to axes specified on your UICamera. If your axes specified on the UICamera match your movement axes, then the same navigation keys used to move the game will also move the menu selection.

In your game movement code, you can simply check UICamera.selectedObject, and if it's not null -- exit early. You're not checking to see if the UI has selection.

trollg

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UICamera Use Keyboard problem
« Reply #2 on: May 21, 2014, 04:54:44 AM »
Hello ArenMook, thanks for the reply.

My UICamera.selectedObject is never null even when the selectedObject is deactivated. Is this somehow a problem? I tried what you suggested by making the UICamera.selectedObject = null when the pause menu is deactivated and early exit my movement code but it didnt work although it was null at first and then got a selectedObject after it was activated...  The same thing happened :(
The strange thing is that when I open the pause menu without pressing the movement buttons (where everything works as they should), when i constantly press the axis keys my buttons dont get automatically selected one after the other, but i have to stop pressing and then press again the key again to select the next one each time as they should. This only happens when the pause menu gets activated when I move my character. And then when i press another key it stops. Its kind of weird actually, since its not as it constantly gets input the same way it does when it works normal. The void OnKey (KeyCode key) function for UIButtonKeys gets called every frame without pressing any key. Also this doesn't happen if I dont set timescale to zero but since its a pause menu I need it.

I would much appreciate a solution to this since I am on the final debugging stage of a big project and my deadline is realy close.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamera Use Keyboard problem
« Reply #3 on: May 21, 2014, 11:53:11 AM »
Selection is quite simple in NGUI. Once you press on something, it becomes selected. Selection is moved to another object when you press on that instead. If you don't clear the selection yourself, it will always point to the last object you pressed on. It's up to you to clear it when you close the menu.

As such, when you open your menu you can give selection to some button whether automatically like in the controller menu example (specified on UIKeyNavigation), or manually via your own script.

Alternatively if you don't want to use the selection you will need to write some logic on your end that checks -- is the main menu open? If yes, don't process movement events.

I'm not quite clear on the last part you wrote. OnKey gets called every frame without pressing any key? Did you check to see what events are coming from Unity's side? This sounds like a serious Unity bug if you're getting OnKey events every frame after pausing the game.

trollg

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UICamera Use Keyboard problem
« Reply #4 on: May 22, 2014, 06:02:31 AM »
I came to the conclusion that this has nothing to do with the movement script since I disabled it and the bug still happens when the axis buttons are pressed and the game paused without stop pressing them. I did an Debug.Log(Input.inputString) on Update and it seems like it constantly gets input...

trollg

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: UICamera Use Keyboard problem
« Reply #5 on: May 22, 2014, 10:14:11 AM »
Ok I found a solution. I left the string values of UICamera script vertical and horizontal axis name blank and it works fine. Maybe those were interfering with the UIButtonKeys scripts I got on my buttons? Anyways it seems to be working fine now. Thanx for your time ArenMook.

Cheers