Author Topic: OnDragOut fires before OnDragEnd  (Read 6160 times)

imperso

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
OnDragOut fires before OnDragEnd
« on: February 17, 2015, 02:11:01 PM »
Hi, Aren.

I have an sprite with UIDragDropItem and UIEventTrigger scripts on it, the latter broadcasts OnDragEnd event.
I have another stationary sprite with UIEventTrigger which reacts on OnDragOver and OnDragOut events.

Then I drag my 1st object over the 2nd (and I see "OnDragOver" in Debug.Log which is OK) and release it.
Then I see in my Debug.Log that first it displays "OnDragOut" and only after that "OnDragEnd"...

As a result I cannot do my Drag'nDrop logic as NGUI thinks that my draggable object already left the area.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnDragOut fires before OnDragEnd
« Reply #1 on: February 17, 2015, 10:20:21 PM »
I am confused by your setup. Why are you doing any of this? What's the point of UIEventTrigger? OnDragEnd is sent to the dragged object and OnDrop is sent to the object underneath it. In most cases you will just stick to UIDragDropItem.OnDragDropRelease -- it's a virtual function. Override it in your own script, do your logic within just like the ExampleDragDropItem.

imperso

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: OnDragOut fires before OnDragEnd
« Reply #2 on: February 18, 2015, 03:42:49 PM »
I redone it.
1) First I removed UIEventTrigger and added onDragOut receiving through UICamera.onDragOut event.
2) Then I overrode OnDragDropRelease(), adding there my custom logic.

Still, onDragOut fires before OnDragDropRelease() despite my dragged object never left the object underneath.

Should I process onDragOut some other way? Or maybe restrict it somehow? Or replace with some alternative?

imperso

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: OnDragOut fires before OnDragEnd
« Reply #3 on: February 18, 2015, 03:57:05 PM »
I think I got it.
In UICamera.ProcessRelease(bool isMouse, float drag) you send OnDragOut ("If there was a drag event in progress, make sure OnDragOut gets sent").

I really don't understand why, but the question is the same - if I receive OnDragOut before OnDragDropRelease() my logic thinks that the object has left the area and will not process OnDragDropRelease() properly. Any solution?

imperso

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: OnDragOut fires before OnDragEnd
« Reply #4 on: February 18, 2015, 05:15:41 PM »
Well, I figured it out.
It was obvious but not very intuitive for starter.
I should have ignore OnDragOut and recheck draggable object whereabouts when getting OnDragDropRelease.
That's it.