Author Topic: Detecting OnDragOver after a non NGUI element is first clicked?  (Read 5213 times)

AnimationMerc

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Hi,

I'm getting started with NGUI and am trying to figure out the details of OnDragOver. I see how it works normally with the OnDrag function on a UIButton (some UI element needs to be selected before dragOver works) but I would like to have it function regardless of what was clicked first. Is there a way to do this?

The end goal is to make a context menu that pops up under the cursor when the LMB is pressed. The button would be selected (OnDragOver/OnDragExit, used like Hover) and activate by the LMB being released (OnPressUp). The exact menu that pops up would depend on what is under the LMB when pressed down. Is OnDragOver even the right way to go about this?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Detecting OnDragOver after a non NGUI element is first clicked?
« Reply #1 on: May 22, 2014, 03:36:00 PM »
If you set UICamera.genericEventHandler to some game object, that game object's scripts will be receiving a copy of all events, whether they were handled or not. So if you wanted to receive OnDragOver / OnDrag / OnDragOut notifications in a single place, make use of the generic event handler.

AnimationMerc

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Detecting OnDragOver after a non NGUI element is first clicked?
« Reply #2 on: May 23, 2014, 10:15:39 AM »
Great, thanks for the help. I'll give it a shot this weekend.

AnimationMerc

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Detecting OnDragOver after a non NGUI element is first clicked?
« Reply #3 on: May 27, 2014, 11:28:29 PM »
That did the trick! Thank you.

AnimationMerc

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Detecting OnDragOver after a non NGUI element is first clicked?
« Reply #4 on: June 01, 2014, 08:40:09 PM »
Well, it worked but led the way to the next problem:
The UIbutton script now registers the Press command (changes color) after the GenericEventHandler was added.

I added a UIEvent Trigger to the button so I could have OnRelease notify but it nothing happens (the UIButton's OnClick does nothing either). Interestingly, I am getting my desired functionality with OnDragOut (mouse down over a non NGUI object, button pops up, drag mouse over then drag mouse off) but I can't get it to register an OnClick or OnRelease.

Any ideas?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Detecting OnDragOver after a non NGUI element is first clicked?
« Reply #5 on: June 02, 2014, 10:35:20 PM »
All I can suggest is debug it, because it works just fine on a regular button.

AnimationMerc

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Detecting OnDragOver after a non NGUI element is first clicked?
« Reply #6 on: June 03, 2014, 02:06:23 AM »
Ok, thank you.