Author Topic: Custom DragRelease layers  (Read 2943 times)

Ace

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Custom DragRelease layers
« on: August 23, 2014, 03:22:53 PM »
Howdy!

I have my own custom script that extends UIDragDropItem.

The way OnDragDropRelease works is that it takes a gameobject surface.

However, there might be things blocking what I want the UI element to be dragged on to. Say I have a ball, and there is a star above the ball, well the star's collider keeps blocking the ball and when I drop the UI item I want to to cast to the ball only (ignoring the star or anything else in front of it).

So in short, how can I get the OnDragDropRelease to have a layermask and only go after the layers I want? (If this was a ray cast I would obviously use a bitshift on the layers, but what do you advise for  this situation?)

I also notice it has a hard time hitting the object I want. Ill put the mouse dead center over my object and it still has a chance to hit something else like the ground. Any general tips on improving drop accuracy (this is really important for my game)?
« Last Edit: August 23, 2014, 05:33:52 PM by Ace »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Custom DragRelease layers
« Reply #1 on: August 23, 2014, 08:11:06 PM »
UICamera's type determines how objects are sorted after getting hit by a raycst. 3D World means it goes by the point of intersection, and if you have colliders in the same place you may run into issues. 3D UI means that objects are taken, then sorted by their widget's depth value.

If you set the type to 3D World, events will also go to rigidbodies rather than colliers, so if your ball is a rigidbody and a star is a child collider, the events will actually be redirected to the ball object. This is useful if you have multiple colliders, but want events to be handled in one place.

In Windward I often have complex objects with multiple colliders on multiple layers, and events going to the rigidbody makes it a trivial matter.

Ace

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: Custom DragRelease layers
« Reply #2 on: August 24, 2014, 09:44:34 AM »
I set it to 3D world, I added a rigidbody, and I find that it only sometimes works.

I will hold the mouse over the object, sometimes it works sometimes it hits the ground. I even turned off the event mask for the ground layer.

Anything else I  might have missed?

To be clear, there is no rigidbody on the ground.
« Last Edit: August 24, 2014, 09:55:56 AM by Ace »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Custom DragRelease layers
« Reply #3 on: August 24, 2014, 07:52:17 PM »
How does it hit the ground if you turned off the event mask for the ground layer?

Did you update to 3.7.1? It had some related changes.

Ace

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: Custom DragRelease layers
« Reply #4 on: August 25, 2014, 07:39:14 AM »
I had 3.6.9 but I just upgraded to 3.7.1

To triple confirm:
I have the UIcamera set to 3D world and its event mask is UI, and Ground.

By that logic, any ground layer object should be NOT be detected right? When I test events over the ground, it still triggers.

Am I mis-understanding how mask works (it means that ground will be IGNORED if selected yes?) or is there some other issue at play. If you direct me to the part of the code where you detect raycast events I'd be happy to take a look and see if there's an issue there.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Custom DragRelease layers
« Reply #5 on: August 26, 2014, 02:08:30 AM »
Event mask determines what is going to be hittable. So if you choose UI and Ground, both of those layers will be hittable.

You have it backwards.

Ace

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: Custom DragRelease layers
« Reply #6 on: August 26, 2014, 08:49:31 PM »
Whether I have the ground layer on or off, it still hits it :(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Custom DragRelease layers
« Reply #7 on: August 27, 2014, 04:25:28 AM »
If the event mask doesn't have some layer checked, then it won't be hittable. Check where the event is coming from. It may be some other camera you forgot about, or maybe you set the generic or fallthrough event handler.

Ace

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: Custom DragRelease layers
« Reply #8 on: August 30, 2014, 12:09:50 PM »
Yes thank you!

There were 2 event scripts!

When I removed the 2nd script it all works now!