Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: ninuson on October 13, 2014, 08:56:29 PM

Title: [solved] How to lose the focus from a UIButton after click?
Post by: ninuson on October 13, 2014, 08:56:29 PM
Hi,

First of all, thanks for a wonderful package! I've been working with it for a while and both the number of features and the support are outstanding.

I ran into something I couldn't find either on the forums or figure out myself. I mix both Unity's native input system and NGUI. I know that it's not ideal and hopefully will refactor everything to NGUI eventually, but I would prefer to solve this problem regardless.

To my problem: I have some things key bound to happen when Input.GetKey(KeyCode.Return) is happening. Specifically, it activates the chat logic. My problem is that if I have clicked on any of the NGUI buttons on the GUI, hitting enter will also click that button. I did not define a behavior for when a key is pressed on the NGUI side for any of the buttons and I don't have an OnSubmit() or KeyBind scripts attached to anything. This sort of leads me to believe it's some default behavior I'm simply not aware of...

I have also tried to play around with UIInput but I wasn't sure how to clear the current "focus". Help would be appreciated!
Title: Re: How to lose the focus from a UIButton after click?
Post by: ArenMook on October 14, 2014, 02:06:24 PM
This happens because when you touch something with NGUI, it gains selection. Selected objects receive keyboard and navigation events, and Return key is one of them.

UICamera.selectedObject = null;