Author Topic: UIWrapContent with dynamic data  (Read 8540 times)

doncarlos91

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 27
    • View Profile
UIWrapContent with dynamic data
« on: May 20, 2016, 03:13:17 AM »
Hi all, i have a shop functionality  with 100+ items , here is my structure

UIScrollView
   UIWrapContent
      Item
      Item
      Item
      etc.
The problem is that , when i`m clicking on the category button , it displays the items in 2-3 seconds and then when it is loads - the UIWrapContent performance works perfectly.

I`m creating items like this
  1.                for (int i = 0; i < dataList.Count; i++) {
  2.                     GameObject item = NGUITools.AddChild(gameObject, prefab);  
  3.                 }
  4.  

Question - how can i prevent this heavy items loading and what is the best way to do this?
Maybe the load prefabs partially , when user scrolls horizontally .
Will be glad for you suggestions and useful code snippets as well.

Thanks in advance
« Last Edit: May 20, 2016, 03:22:23 AM by doncarlos91 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIWrapContent with dynamic data
« Reply #1 on: May 21, 2016, 09:48:41 PM »
UIWrapContent is used to recycle items. For example if you have 100 items, but only 10 are visible, you need to add 10+2=12 children at most, as they will be reused when they go out of range.

In the current game I'm developing I have a scroll view where I generate preview thumbnails for all the items within it which involves rendering them to render textures. I made it so that it only renders 1 item per frame rather than all of them at once. This makes items appear one at a time (and I can make them fade in if I want), but also means that there is no performance hit as I don't try to draw them all at once.