Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: Shifty Geezer on January 19, 2014, 04:20:16 PM
-
I have a selector (scrollview list of buttons) that appears when I long-press a button. I want any press outside this widget to cause it to close, whether that's on the game background or another NGUI widget.
-
Hey there.
I have this in my game, i made it with a big ( giant ) widget behind the main one, with a big collider and an UIButton script that sends an event to the widget that needs to be closed.
-
NGUI sents OnSelect(false) when another object gets pressed.
-
I'm clicking buttons within the scrollview. The scrollview's collider itself never registers these presses, so I can't use 'OnSelect(false)' with the scrollview to register a press outside the scrollview. I can't use the button's OnSelect to notify the scrollview to close either in case the next button pressed is within the scrollview.
-
yeah, a panel/scrollview etc should best trigger a different event like OnPressOutside which is triggered when clicking outside the boundaries (but is not triggered when clicking something like a different button inside the panel)
-
In case someone else has this issue, here's how I've solved it.
On my pop-up panel, I have an empty background widget with collider that fills the screen and contains the selection widget. The selection widget works as normal, and if I click outside of it I hit the collider of the background widget. I have to deactivate all other components when it pops up though. I have a little SetEnabled() script that deactivates boxcolliders that I apply on the root containers for my various panels.
I think it'd be nice and sensible to have a 'pop-up' widget type that automates this as it's a common feature. It would be easy to create a prefab that has the background widget and actual component but the deactivation of everything else might be tricky. If there's a way to 'z-sort' controls, this deactivating step wouldn't be needed making the whole thing even easier. A 'pop-up' script would add a full-screen widget and a widget within set up to capture the outside box events.