Author Topic: What options do we have to hide objects outside a scrollview?  (Read 20483 times)

dandrea

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 2
  • Posts: 23
    • View Profile
What options do we have to hide objects outside a scrollview?
« on: November 18, 2014, 10:36:46 AM »
The obvious one is using Soft clip as clipping, but this one usually turns an otherwise fluid framerate into a crawl on mobile devices.

So I use to go by with the great Constrain but Dont Clip option, and make sure I have UI elements and backgrounds covering the areas outside the scroll view, and this usually works well.

I just hit a situation where hiding objects that are entirely outside the scrollview would suffice and thus I can continue in the Constrain but Dont Clip Happy Land.

I guess that having a UIWidget as the base of the scrollview elements where I can set the alpha to 0 is good, but I'm having a hardtime finding out how to detect someone is entirely out of the scrollview.

Ideas?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: What options do we have to hide objects outside a scrollview?
« Reply #1 on: November 19, 2014, 03:24:10 PM »
Fluid framerate into a crawl? Soft clip is just alpha clip. It doesn't have much of an effect on framerate. Certainly nothing noticeable in my tests. Soft clipping automatically culls objects that are outside it, and they aren't drawn.

dandrea

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 2
  • Posts: 23
    • View Profile
Re: What options do we have to hide objects outside a scrollview?
« Reply #2 on: November 19, 2014, 03:35:16 PM »
Well, what can I say? I just saw it happening. I did the tests and the sole and single culprit was Soft Clip. Constrain but Dont Clip just makes things run smooth.

I heard that mobile devices, specially Apple ones, won't deal that well with alpha clipping, but maybe there are a few things I'm missing miserably, it won't be the first time.

Any ideas?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: What options do we have to hide objects outside a scrollview?
« Reply #3 on: November 19, 2014, 04:13:19 PM »
Everyone who uses NGUI uses soft clipping. If doing so truly slowed app's performance down to a crawl, it would have been spotted and brought up a very long time ago. I myself have published a game on Android and iOS that used soft clipping in a couple of places, so I can safely say that your culprit lies elsewhere. Check the quality settings, make sure you're on the latest versions of everything, and try building NGUI's examples, like the scroll view example. All of NGUI's examples use soft clipping.

dandrea

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 2
  • Posts: 23
    • View Profile
Re: What options do we have to hide objects outside a scrollview?
« Reply #4 on: November 19, 2014, 07:42:12 PM »
The only thing I change between the builds is the clipping settings. Nevermind.

roady

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: What options do we have to hide objects outside a scrollview?
« Reply #5 on: December 29, 2014, 10:33:45 AM »
Was there any solution for this?

I'm having the issue that getting error:
Too many vertices on one panel

So object outside camera view (and scroll) should be completely hidden.

  1. ticketScroll.GetComponent<UIScrollView> ().onDragStarted += onViewDragStart;
  2. ticketScroll.GetComponent<UIScrollView> ().onStoppedMoving += onViewDragFinish;
  3.  
  4. private void onViewDragFinish() {
  5.         isDraggning = false;
  6. }
  7.        
  8. private void onViewDragStart() {
  9.         isDraggning = true;
  10. }
  11.  
  12. void Update(){
  13.         if (isDraggning) {
  14.                 foreach (UIWidget card in cardList) {
  15.                         // HOW TO CHECK IF INSIDE VIEW?
  16.                 }
  17.         }
  18. }

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: What options do we have to hide objects outside a scrollview?
« Reply #6 on: December 29, 2014, 11:01:42 AM »
Wow you must have thousands of widgets to have too many vertices in one panel. If you consider a quad is 5 vertices, admitting you have only one widget on each object and the limit is 65000 vertices(I think this uses the same limit as Unity does on Meshes), you would have 13000 widgets. Even if you have 2 widgets for each objects it still 6500 objects in your panel.
What are you doing ? :o
If you need to have so much widgets in one panel, you should consider using UIWrapContent.

roady

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: What options do we have to hide objects outside a scrollview?
« Reply #7 on: December 29, 2014, 11:13:39 AM »
Upgrading a companies old app, having only 42 child objects.
each object is a little more complex with a lot of UILabels.

tried putting a UIWrapContent but doesn't quite understand how it works, didn't work.

No idea on how to use logic with:
NGUITools.SetActive(gameObject, show);

dandrea

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 2
  • Posts: 23
    • View Profile
Re: What options do we have to hide objects outside a scrollview?
« Reply #8 on: December 29, 2014, 06:11:21 PM »
Labels, you say... How much text did you put in them?

If I remember correctly, I got this once by putting too much characters in a single label. I solved it by distributing it through some more labels.

roady

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: What options do we have to hide objects outside a scrollview?
« Reply #9 on: December 30, 2014, 06:58:22 AM »
Each item around 150 labels, not many characters each (2-30chars).
Then around 120 uisprites that uses same atlas.

trying to optimize them but would really love a solution to hide each item when outside camera view.
Tried using this without success

widget.hideIfOffScreen = true;

roady

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: What options do we have to hide objects outside a scrollview?
« Reply #10 on: December 30, 2014, 08:10:58 AM »
in the DRAG Update I put this script to check if item is inside view, else hide it.

Note here that I tell the class to hide itself, the base gameobject cannot be hidden because that will mess upp the scroll.
The class hides things inside.

Maybe not a pretty solution but it seems to work for now.

  1. // calculate size and scale
  2.                         UIRoot mRoot = GameObject.FindObjectOfType (typeof(UIRoot)) as UIRoot;
  3.                         float ratio = (float)mRoot.activeHeight / Screen.height;
  4.                         int width = (int)Mathf.Ceil(Screen.width * ratio);
  5.                         int height = (int)Mathf.Ceil(Screen.height * ratio);
  6.  
  7.                         // item width
  8.                         float cWidth = ticketPlaceholder.GetComponent<UIGrid>().cellWidth;
  9.  
  10.                         // camera bounds
  11.                         float x = ticketScroll.GetComponent<UIPanel> ().clipOffset.x;
  12.                         float cLeft = x - (width/2f);
  13.                         float cRight = x + (width/2f);
  14.  
  15.                         int counter = 0;
  16.                         foreach (CardController card in ticketsCardList) {
  17.                                 // item bounds
  18.                                 float itemXCenter = ( cWidth * counter );
  19.                                 float itemLCenter = itemXCenter - (cWidth/2f);
  20.                                 float itemRCenter = itemXCenter + (cWidth/2f);
  21.                                 // is item visible, do not hide whole item, must leave base UIWidget, hide inside
  22.                                 bool isVis = (itemRCenter > cLeft && itemLCenter < cRight ) || (itemLCenter < cRight && itemRCenter > cLeft ) || (itemLCenter > cLeft && itemRCenter < cRight );
  23.                                 card.Show(isVis);
  24.                                 counter++;
  25.                         }

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: What options do we have to hide objects outside a scrollview?
« Reply #11 on: December 30, 2014, 11:03:51 AM »
Each item around 150 labels, not many characters each (2-30chars).
Then around 120 uisprites that uses same atlas.

trying to optimize them but would really love a solution to hide each item when outside camera view.
Tried using this without success

widget.hideIfOffScreen = true;

Ok let's do some maths.
Each characters is a quad. You have around 15 chars on each labels, so 15x5 =75 vertices for each label.
You have for each item, 150 labels, so 150x75 = 11250 vertices on one item.
You have 40 items, so 40x11250= 450 000, it's almost 7 times the limit... (And I didn't take in count the UISprites...)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: What options do we have to hide objects outside a scrollview?
« Reply #12 on: December 30, 2014, 02:49:27 PM »
A quad is 4 vertices, r.pedra, not 5. That's why it's a "quad". Ie: "four". :P

Outline effect multiplies vertex count by 5. Shadow effect -- by 2. It's quite easy to hit the 65k vertex limit by abusing the outline effect. Also note that UIPanel has a "cull while dragging" option that will cull things that are not visible automatically.

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: What options do we have to hide objects outside a scrollview?
« Reply #13 on: January 05, 2015, 06:06:09 AM »
A quad is 4 vertices, r.pedra, not 5. That's why it's a "quad". Ie: "four". :P

Outline effect multiplies vertex count by 5. Shadow effect -- by 2. It's quite easy to hit the 65k vertex limit by abusing the outline effect. Also note that UIPanel has a "cull while dragging" option that will cull things that are not visible automatically.

Errrr my bad, I was very tired  :P