Author Topic: UIPanel with Clipping Does Not Cull OnClick for Out Of Bounds Objects  (Read 4796 times)

DCalabrese

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 23
    • View Profile
This seems to be a problem in all versions of NGUI in Unity 5. When we create an object with a UIPane, and apply Soft Clip, then place objects inside of the panel, the clipping works fine. We can move objects all around, no problem. However - NGUI is now allowing objects that have the UIEventTrigger component and are outside of the clipping zone to still receive OnClick events. This is obviously causing us a bit of a problem, as if we have a draggable list in the middle with buttons above and below it, we cannot click on the buttons above and below as the hidden objects takes the input instead!

Is anyone else seeing this issue as well? Are there any known fixes available? For reference we are running NGUI 3.8.2 in Unity 5.0.1p2, however the issues persists with other combinations of NGUI 3 and Unity 5 as well.

Thank you in advance!

DCalabrese

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 23
    • View Profile
Bumping this as the issue is causing us to possibly have to redesign our entire UI...

DCalabrese

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 23
    • View Profile
Figured out a fix. This can be improved as it doesn't take multiple parent UIPanels into consideration among other things, but it fixes the issue.

In UIScrollView.cs, on line 879, paste the following block of code.

  1.                 // Quick hack implementation of a fix for NGUI failing to clip colliders in UIPanels.
  2.                 UIPanel parentPanel = NGUITools.FindInParents<UIPanel>(gameObject);
  3.                 float panelTop = parentPanel.GetSides(parentPanel.transform)[1].y;
  4.                 float panelBottom = parentPanel.GetSides(parentPanel.transform)[3].y;
  5.                 BoxCollider[] childColliders = GetComponentsInChildren<BoxCollider>();
  6.                 foreach(BoxCollider thisCol in childColliders)
  7.                 {
  8.                         Bounds goBounds = thisCol.GetComponent<BoxCollider>().bounds;
  9.                         float objBottom = parentPanel.transform.InverseTransformPoint(goBounds.min).y;
  10.                         float objTop = parentPanel.transform.InverseTransformPoint(goBounds.max).y;
  11.  
  12.                         thisCol.enabled = (objBottom < panelTop && objTop > panelBottom);
  13.                 }
  14.  

With that, NGUI once again properly culls colliders that are outside of a panel. Hope this helps anyone else plagued with this problem!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
I am a bit confused by this question. NGUI's events get clipped if your event type is set to 2D UI or 3D UI. If it's not "UI" type, then events won't be checked to see if they were clipped by the panels.

DCalabrese

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 23
    • View Profile
In the case of these objects, it's a standard UI setup, and the objects use the EventTrigger component to send the events. Where do I set the Event Type for the objects?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
It's set on the UICamera that sees them.

DCalabrese

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 23
    • View Profile
They are indeed set to that proper event, however the problem persists. Now my scene does have a series of cameras to have different layered shader effects and the like, so there could be something related to that.