Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: kobilica on July 22, 2014, 10:13:10 AM

Title: Hover+pressed like event for control buttons
Post by: kobilica on July 22, 2014, 10:13:10 AM
Hello, I am bit new in scripting and I don't really get how to do custom events in NGUI.

I know OnClick, OnPress etc events, but they don't all act like I want them to act.

The game will be on mobiles. This means it will work on touch.

Now, I want hover behaviour (OnHover) but that it will work on touch. So, you push finger on display, and you then can trigger all buttons you touch with it or untrigger, if you stop touching them.

Is this possible the easy way..? Thanks!
Title: Re: Hover+pressed like event for control buttons
Post by: ArenMook on July 22, 2014, 09:26:02 PM
When you press on the screen, you get OnPress(true). When you start dragging something, you get OnDragStart, followed by many OnDrag notifications. When you drag the mouse/touch away from an object, you get OnDragOut. When you drag over another object, you get OnDragOver. When you release the touch, you get OnDragEnd, OnPress(false) and OnDrop (on the object you dropped the item onto).
Title: Re: Hover+pressed like event for control buttons
Post by: kobilica on July 23, 2014, 03:49:05 AM
Ok looks like I was close, I used OnPress, OnDragOut and OnDragOver.. but it was still buggy.

Thanks for clarification!

Gonna code this right now.. will write back :)
Title: Re: Hover+pressed like event for control buttons
Post by: kobilica on July 23, 2014, 04:22:31 AM
Ok, it works 90%.

Only problem is, when I click empty space( no UI colliders) and then drag touch pointer/mouse to buttons, they don't react.

That is why I added invisible background sprite with collider without actions, to fix this 'bug'.

Thanks :P
Title: Re: Hover+pressed like event for control buttons
Post by: kobilica on July 23, 2014, 05:06:55 AM
Ok, solved 100%  ;)

I added background sprite which is 1px big (width and height) and has alpha of 1! (if alpha is 0, it is disabled).
Title: Re: Hover+pressed like event for control buttons
Post by: ArenMook on July 23, 2014, 07:42:51 PM
...or you could have just created a widget. Widgets are invisible.

ALT+SHIFT+W.
Title: Re: Hover+pressed like event for control buttons
Post by: kobilica on July 24, 2014, 09:45:28 AM
Ok thanks, will do! Should have red documentation more stronger..

"Self-slap"