Author Topic: Culling out-of-panel widgets.  (Read 7095 times)

zoombapup

  • Guest
Culling out-of-panel widgets.
« on: August 19, 2013, 05:39:24 AM »
I don't get it. I mean it seems pretty common functionality to have scrollable lists of widgets right? I'm doing inventory/crafting UI stuff and this notion of scrollable lists is all over there.

Anyway, its a problem for me that widgets outside of a panel are still interactive. If a widget is outside of its parent panel, it should be non-interactive. So I'm looking for the best place to make that work. It looks like UpdateGeometry in the UIWidget.cs actually does a call to get its visibility within its parent. So my question is, do you think thats the right place to then disable the collider for that widget? (clipping is a seperate issue right now). Obviously not all UIWidgets have colliders attached, but I can worry about making the code more flexible once I find the appropriate point to do the test.

Anyone done this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Culling out-of-panel widgets.
« Reply #1 on: August 19, 2013, 08:54:10 AM »
"clip raycast" option is turned on by default on the UICamera. Did you turn it off?

zoombapup

  • Guest
Re: Culling out-of-panel widgets.
« Reply #2 on: August 19, 2013, 12:02:11 PM »
No, its on. I'm guessing its not doing that because I've got child items within a child gameobject with a UIGrid attached, rather than directly decending from panel. So does clipraycasts do a check against parent panels that are clipping?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Culling out-of-panel widgets.
« Reply #3 on: August 19, 2013, 09:43:53 PM »
It won't work if you have nested panels. The first panel above the collider you're clicking on must be the clipped panel. If you have an in-between panel, it won't work (and neither will clipping).

zoombapup

  • Guest
Re: Culling out-of-panel widgets.
« Reply #4 on: August 20, 2013, 12:29:49 AM »
It hasn't got a nested panel, its got a child gameobject with UIGrid which then has child controls (the icons).

So its:

InventoryItems <-- top level for the scroll part
      ---Contents <-- the UIGrid object that has the child controls attached (and my script to populate the children)
               --- Item <-- the icons... xN
               --- Item
               --- Item

So its not clipping against InventoryItems rect area. Of course this InventoryItems rect is then contained within another panel (so Inventory items can scroll its contents).

Out of interest, why would clipping not clip against all of its parents who clip? I'm curious as to why clipping isn't just a "cull any of my children recursively"? Surely this is what you want when you clip something, that its child contents not be active outside the parent, no matter where they are in the child heirarchy?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Culling out-of-panel widgets.
« Reply #5 on: August 20, 2013, 02:07:04 PM »
Because of how NGUI works. Widgets are drawn by panels, and only the panel that draws the widgets can clip them.

zoombapup

  • Guest
Re: Culling out-of-panel widgets.
« Reply #6 on: August 20, 2013, 02:21:32 PM »
Ok, so how would you recommend making a scrollable panel with a grid of children? It has to be able to have a scrollbar and scroll the contents.

I added the "contents" gameobject because it seemed to make layout easier instead of having the grid on the panel, because grid positions the controls in the wrong place unless you can offset it within the panel (if you could offset the grid somehow maybe that'd work).


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Culling out-of-panel widgets.
« Reply #7 on: August 20, 2013, 02:39:14 PM »
You can have a grid no problem. You just can't nest clipped panels. Also if you do this:

UIPanel (clipped)
- UIPanel (not clipped)
-- Widget 0
-- Widget 1
-- Widget 2

...this also won't work, because the second panel will cancel out the clipping of the first.

zoombapup

  • Guest
Re: Culling out-of-panel widgets.
« Reply #8 on: August 20, 2013, 02:49:16 PM »
The problem is that the grid position is incorrect unless I add a child gameobject below the topmost panel and offset it, then add the grid items to that offset gameobject.

Basically the grid needs positioning within the parent panel, because by default it isn't in the right place (I don't know what the default position is, but its completely wrong place for a grid of controls).


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Culling out-of-panel widgets.
« Reply #9 on: August 20, 2013, 02:52:23 PM »
"Isn't in the right place"? Grid is just a script on a game object. It's up to you to position it how you want it to be. I'm not sure I understand why you need another game object to offset it.

zoombapup

  • Guest
Re: Culling out-of-panel widgets.
« Reply #10 on: August 20, 2013, 03:06:14 PM »
Well, I've got a grid of icons to place within the scrollable area. If I add a grid to the panel itself, then the origin of the grid is in completely the wrong position for the icons which are meant to stay within the grid. In part I guess its just how the grid works, but I added the parent gameobject for the grid so that I could move it around within the panel to get the correct grid positioning.

I guess I'll give it a try with an offset value for the grid and see how that works.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Culling out-of-panel widgets.
« Reply #11 on: August 21, 2013, 10:47:07 AM »
Yes, the grid needs to be on an object separate from the panel. The hierarchy is always:

UIPanel
- Grid (offset to how you need it to be)
-- Widget 0
-- Widget 1
-- Widget 2

zoombapup

  • Guest
Re: Culling out-of-panel widgets.
« Reply #12 on: August 21, 2013, 01:10:25 PM »
Right, so with that exact setup the widgets within the panel aren't clipped/culled.

Should they be?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Culling out-of-panel widgets.
« Reply #13 on: August 22, 2013, 11:17:00 AM »
Yes they should. Select your widget and open the Panel Tool. Does the correct (clipped) panel get highlighted? If not, then there's your problem. If yes, make sure you have shaders enabled to begin with, and that the clipped shaders were not moved out of the Resources folder they came in. Lastly, make sure the UI atlas uses Unlit/Transparent Colored shader.

zoombapup

  • Guest
Re: Culling out-of-panel widgets.
« Reply #14 on: August 22, 2013, 01:24:16 PM »
Its not the visual clipping thats the issue (although I'll have to look at that, shouldnt the shader for clipping controls be transparent/coloured alpha clip?)

The problem is that the controls still have working colliders outside of the clip area, so the player can click on them still when outside of the panel.