Author Topic: Responding to Click Events  (Read 6128 times)

Lypheus

  • Guest
Responding to Click Events
« on: April 11, 2012, 10:51:48 PM »
Just working with the UITable component here and I'm wondering what the best practice is for responding to mouse events - i'm using a GO with a box collider but not able to catch OnMouseEnter etc... To clarify, the GO is an empty GO with two labels as child objects, the GO itself has the collider and click script attached.  I've seen the event get fired once if i move the mouse around enough, but it's almost as if the collider is not travelling with the GO somehow within the table.
« Last Edit: April 11, 2012, 11:11:39 PM by Lypheus »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Responding to Click Events
« Reply #1 on: April 11, 2012, 11:21:48 PM »
Off the top of my head I can't tell you what's wrong there. I generally don't attach anything to the table though. I prefer to attach colliders to widgets -- such as the background widget. That said though, attaching to the table should work just fine. I'd take a look at your camera there and make sure that your near/far clipping planes are set up correctly (shouldn't be a problem if you are using a 2D camera and used the Create UI Tool to make it).

Lypheus

  • Guest
Re: Responding to Click Events
« Reply #2 on: April 11, 2012, 11:42:42 PM »
Well searching through the docs I'm seeing that my handler should be different, using the camera generated and this code is attached to the widget with box collider: http://pastie.org/3772348 (collider is visible as i run the code).  Had to adjust z-index of texture background as well but still no love at this point, not sure whats up.  Should be as easy as accepting a click event off that collider??  The collider is attached to each 'item' i add to the list.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Responding to Click Events
« Reply #3 on: April 11, 2012, 11:44:50 PM »
You should be able to see the colliders by simply selecting the game object in inspector.

If nothing else, add a script that watches UICamera.hoveredObject and prints its name.

Lypheus

  • Guest
Re: Responding to Click Events
« Reply #4 on: April 12, 2012, 12:06:32 AM »
So, using the hoverObject approach reveals that the parent Panel is receiving the mouse events.  I need to sink the events down the hierarchy so that child labels receive them as well.  Here is what my object hierarchy looks like: http://screencast.com/t/OWenK9JXmd .  So, if i disable the collider on the panel then the InventoryItem receives events as expected, however it no longer responds to dragging.  So what I need is to allow for specific events to sink down the hierarchy.

This must be handled at some point, using a UITable to contain menu items seems an obivous use case - am I missing something perhaps that is causing this?  I've tried mucking a bit with the pos:z value but its a local value so somehow i need to ensure the label sits on top of the parent panel to intercept events when its clicked on.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Responding to Click Events
« Reply #5 on: April 12, 2012, 12:09:26 AM »
Why is the panel receiving events? Remove the collider from it, or move its collider back so its not covering your items (+Z).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Responding to Click Events
« Reply #6 on: April 12, 2012, 12:10:15 AM »
To clarify: You can have drag scripts on your items, and on your panel's collider. Just make sure the panel's collider doesn't cover your items. Items must be in front.

Lypheus

  • Guest
Re: Responding to Click Events
« Reply #7 on: April 12, 2012, 12:10:27 AM »
Alright I found it - the collider of the widget's Center:Z needed to be adjusted to -1, all is well now - thanks!