Author Topic: [FEATURE REQUEST] Hit test filter  (Read 12076 times)

Wahooney

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
    • View Profile
[FEATURE REQUEST] Hit test filter
« on: January 22, 2014, 03:26:49 AM »
I'm in a delicate situation where the default hit box is causing problems with my widgets, as my controls are hexagonal and in some cases tesselating, causing overlaps. I know that I can use mesh colliders, but that would mean I'd need a mesh for every size of button I intend on having and that doesn't sound like a fun night out.

Enter NGUI.IHittable interface! (name open to change)

My proposed interface would have a bool IsHit (Vector3); method that provides the hit location in the widget's local coordinates. The bool return would tell NGUI whether the widget was in fact hit or not based on any methodologies the coder decides on, in my case, does it fit in a hexagon of arbitrary size/orientation.

The implementation shouldn't be difficult, the UICamera can collect all behaviors OnEnable / Start / Awake / Refresh / whatever, put them in a Dictionary<Widget, NGUI.IHittable>, when the widget is hit and it has an entry in the dictionary it can first check if the paired NGUI.IHittable.IsHit returns true, if not go to the next possibly hit widget until a widget is in fact fully hit.

Thoughts?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [FEATURE REQUEST] Hit test filter
« Reply #1 on: January 22, 2014, 05:14:06 AM »
I'll push an update in about an hour or two that adds UIWidget.hitCheck delegate. You can set it to a function of your choice. Inside the function you get a world-space position, and it's up to you to determine if it's within the bounds of your choice or not. Return 'true' or 'false'.

Wahooney

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
    • View Profile
Re: [FEATURE REQUEST] Hit test filter
« Reply #2 on: January 22, 2014, 05:50:06 AM »
Hell, I'll take it!

Thanks man!

:D :D

Wahooney

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
    • View Profile
Re: [FEATURE REQUEST] Hit test filter
« Reply #3 on: January 24, 2014, 03:32:10 AM »
There is a bit of a bug / missing feature / whatever.

UIWidget.hitCheck is only performed if a hit test actually hit multiple colliders, if it only hit a single collider it doesn't do the test, and if I read the code correctly it would appear that it doesn't happen in World Events either.

I've checked, it's a simple fix :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [FEATURE REQUEST] Hit test filter
« Reply #4 on: January 24, 2014, 08:22:15 AM »
My mistake, I'll get that fixed, thanks.