Author Topic: buttons attached to a UIDrag Panel Contents gameobject  (Read 5850 times)

serioustommy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
buttons attached to a UIDrag Panel Contents gameobject
« on: May 04, 2012, 09:21:25 AM »
A quick general question - when you have a gameobject with a collider, and you have a button attached to that gameobject, is it the expected behaviour that the button will never receive events like OnClick because the parent gameobject intercepted all the events? Is moving the button out so that it's on the same hierarchical level as the gameobject the only way to make it work?

Here's the scenario I'm working with. I have a UIDraggable Panel gameobject that contains several UIDrag Panel Contents gameobjects. I would like to add a button to the UIDrag Panel Contents gameobject and have the button react to mouse over/up/click events, which it currently doesn't because I suppose the collider in UIDrag Panel Contents gameobject has intercepted them, regardless the depth on the button.

The behaviour that will be really good to have is that any button underneath a UIDrag Panel Contents gameobject will react the same way as a clickable button/link under iOS. i.e. when a button is pressed it'll react normally, but if you then begin dragging the button will be released and the drag event passed onto the UIDrag Panel Contents gameobject so that the whole panel is dragged instead.

Currently I can't find a way to simulate this myself as the button doesn't seem to receive any events at all, and it's really messy having the button outside of the UIDrag Panel Contents gameobject as they belong together.

Just wondering if it's something that I'm doing wrong and if my suggestions make sense?

thanks,
Tommy

Matthias

  • Guest
Re: buttons attached to a UIDrag Panel Contents gameobject
« Reply #1 on: May 04, 2012, 09:30:22 AM »
I have the exact same setup and it works fine if you make sure that the BoxCollider that is supposed to have priority is the nearest to the camera in Z space. The BoxColliders position is the key, the rest doesn't matter. Whatever the ray from the camera hits first is triggered. You can debug this by checking the green collider gizmo in the Scene view.

Matthias

  • Guest
Re: buttons attached to a UIDrag Panel Contents gameobject
« Reply #2 on: May 04, 2012, 09:32:09 AM »
Oh, that reminds me of another issue with that though. Colliders don't get clipped, so you can click on stuff outside the draggable panel (just the first one that is partially clipped).

serioustommy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: buttons attached to a UIDrag Panel Contents gameobject
« Reply #3 on: May 04, 2012, 09:54:09 AM »
Hmm I did try changing the collider z and it didn't work for me that's why I thought maybe in general any children won't receive any events if the parent has a collider.

Just tried it again and it seems to work, thanks.

However would be good to make it an optional behaviour so that dragging can be initiated when pressing on any part of the draggable panel, even if the initial press is intercepted by a button that's a child of the draggable panel. This is the same behaviour as dragging contents on ios/android.

thanks!
Tommy

serioustommy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: buttons attached to a UIDrag Panel Contents gameobject
« Reply #4 on: May 04, 2012, 10:55:31 AM »
nevermind, turns out it'll work like I described if I just attach UIDragPanelContents to the button  :)