Author Topic: Hover+pressed like event for control buttons  (Read 4737 times)

kobilica

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Hover+pressed like event for control buttons
« 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!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Hover+pressed like event for control buttons
« Reply #1 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).

kobilica

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Hover+pressed like event for control buttons
« Reply #2 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 :)

kobilica

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Hover+pressed like event for control buttons
« Reply #3 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

kobilica

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Hover+pressed like event for control buttons
« Reply #4 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).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Hover+pressed like event for control buttons
« Reply #5 on: July 23, 2014, 07:42:51 PM »
...or you could have just created a widget. Widgets are invisible.

ALT+SHIFT+W.

kobilica

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Hover+pressed like event for control buttons
« Reply #6 on: July 24, 2014, 09:45:28 AM »
Ok thanks, will do! Should have red documentation more stronger..

"Self-slap"