Author Topic: Sample for UIWrapContent with 100s of items  (Read 6303 times)

amraffay

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 37
    • View Profile
Sample for UIWrapContent with 100s of items
« on: May 24, 2016, 06:25:21 AM »
Hi there,
There is no example scene or even a step by step tutorial for using UIWrapContent to display 100s of items that scroll fast.
Can you please provide one in your next update?
Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sample for UIWrapContent with 100s of items
« Reply #1 on: May 24, 2016, 04:49:09 PM »
What about example 14? The number of items inside the UIWrapContent is really up to you. I always suggest to count the number of visible items and add 2. For example if the scroll view is meant to display up to 10 items, put 12 children inside it. The script will reuse existing items and will call UIWrapContent.onInitializeItem delegate when an item gets repositioned and needs to have its data repopulated accordingly. So literally all you have to do is subscribe to that delegate, then inside the function set the item's data as you need it to be.

amraffay

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: Sample for UIWrapContent with 100s of items
« Reply #2 on: May 26, 2016, 06:12:25 AM »
Example 14 seem to have hard coded data.
A good example of UIWrapContent'd be

A List with lets say 12 gameobject (list items that have a text and a remote image). When user hits play, a script assign 100 items to this list and uiwrapcontent is able to display 100s of items.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sample for UIWrapContent with 100s of items
« Reply #3 on: May 26, 2016, 12:39:52 PM »
That's the thing though. Hitting "play" will only assign those 12 objects, not all 100. Only visible objects receive the onInitializeItem delegate call. That's what makes it possible to reuse those 12 items to effectively make all 100 visible by scrolling. Objects just get reused and reinitialized.

amraffay

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: Sample for UIWrapContent with 100s of items
« Reply #4 on: May 26, 2016, 02:44:05 PM »
I understand virtualization that but current example is "static".
A better example contains a separate script with a List<string> of 100s items and when user scrolls this data is passed to visible items on runtime.
An example or a tutorial'd be helpful for newbies like me who can dynamic list controls with it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sample for UIWrapContent with 100s of items
« Reply #5 on: May 27, 2016, 10:18:11 PM »
It's quite simple:
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(UIWrapContent))]
  4. public class DynamicData : MonoBehaviour
  5. {
  6.     void Awake ()
  7.     {
  8.         GetComponent<UIWrapContent>().onInitializeItem = delegate (GameObject go, int wrapIndex, int realIndex)
  9.         {
  10.             go.GetComponentInChildren<UILabel>().text = realIndex.ToString();
  11.         };
  12.     }
  13. }
Of course you'll want to do something more complex than just setting the label's text to the index, but it should get you started.

amraffay

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: Sample for UIWrapContent with 100s of items
« Reply #6 on: May 28, 2016, 03:31:57 AM »
That does the job thank you.
but how do i add list selection?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sample for UIWrapContent with 100s of items
« Reply #7 on: May 29, 2016, 11:44:00 AM »
List selection?

amraffay

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 37
    • View Profile

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sample for UIWrapContent with 100s of items
« Reply #9 on: June 04, 2016, 02:14:59 PM »
So what's the question? How to have selectable items? That would be the UIToggle script. It's no different from anything else. In your onInitializeItem delegate you set the contents' values, such as label text or toggle's state.

amraffay

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: Sample for UIWrapContent with 100s of items
« Reply #10 on: June 05, 2016, 10:47:40 AM »
So what's the question? How to have selectable items? That would be the UIToggle script. It's no different from anything else. In your onInitializeItem delegate you set the contents' values, such as label text or toggle's state.

Thanks, almost there.

How should i handle remote images? as they slow down scrolling speed? should i get them as texture or sprite? how should i approach whole image thing with NGUI?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Sample for UIWrapContent with 100s of items
« Reply #11 on: June 06, 2016, 06:28:11 AM »
That's sorta up to yourself, mate. ;)

Generally, if you get pictures from "outside" the compiled build, it's recommended to use UITexture, as you can't really pack a new Atlas with external images.

As for when and how to cache them, that depends on how much you got. You can have some script outside of the wrapcontent download the images and use a placeholder until they are cached, or have some sort of cap on how many you want to cache, or even look at which elements are shown now, to predict which will be shown next (say +-10 elements) and only cache those. The complexity is really up to yourself.

amraffay

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: Sample for UIWrapContent with 100s of items
« Reply #12 on: June 11, 2016, 05:27:29 PM »
@ArenMook

I recently purchased NGUI and atleast expect to have a proper List Control with variable height as well as vertical and tile layout (where number of columns are based on available width).

Can you please provide a proper list control in your next update? i purchased NGUI for only List control because Unity's doesnt scroll well. Now if you provide that control it will not just make current customers happy but future too.

Waiting