Author Topic: List with Selection that can render 100s of items  (Read 2614 times)

amraffay

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 37
    • View Profile
List with Selection that can render 100s of items
« on: May 02, 2015, 01:11:51 PM »
Hi,

I'm creating an app like game which will have list with complex items (icon, label and accesssory).
How can i achieve something like that with NGUI?
Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: List with Selection that can render 100s of items
« Reply #1 on: May 02, 2015, 10:09:27 PM »
Just do it? I am not sure I understand the question. If you want to do it very efficiently, look at endless scroll views.

amraffay

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: List with Selection that can render 100s of items
« Reply #2 on: May 03, 2015, 02:52:41 AM »
I'm actually new to NGUI so what are the steps to achieve that?
Should i use scrollView with Grid? and add items dynamically using NGUITools.AddChild?
or something else?

Thanks

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: List with Selection that can render 100s of items
« Reply #3 on: May 03, 2015, 04:22:30 AM »
Make each entry as a prefab and add them when the scrollview is created? You can have a grid place them. Look in the examples folder at the endless scrollview scene to see how it could be done.

amraffay

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: List with Selection that can render 100s of items
« Reply #4 on: May 05, 2015, 08:55:12 AM »
I'm actually adding contents dynamically using
  1. NGUITools.AddChild (list.gameObject, galleryItem);
  2. list.Reposition ();
  3.  

However problem is as galleryitem is using UIDragScrollView which require reference to scroll vew (in my case on runtime)
So i have this code attached to galleryitem
  1.         void Start () {
  2.        
  3.                 GetComponent<UIDragScrollView> ().scrollView = GameObject.Find("Scroll View").GetComponent<UIScrollView>();
  4.  
  5.  
  6.         }
It doesnt look efficient, as ill b adding 100s of items on runtime
What'd you suggest?

Thanks

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: List with Selection that can render 100s of items
« Reply #5 on: May 05, 2015, 05:15:32 PM »
Have a reference to the scrollview in and do this:

  1. //public UIScrollView scrollView; //set in the spawner prefab
  2. var go = NGUITools.AddChild (list.gameObject, galleryItem);
  3. go.GetComponent<UIDragScrollView>().scrollview = scrollView;
  4. list.Reposition ();
  5.  

The getcomponent isn't too bad, but .Find suuucks. :)

amraffay

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: List with Selection that can render 100s of items
« Reply #6 on: May 05, 2015, 11:35:05 PM »
Much better now, Thanks :)

Now the remaining issue is how can i make list item selectable and listen to change event?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: List with Selection that can render 100s of items
« Reply #7 on: May 07, 2015, 06:18:45 PM »
Put a UIToggle on the items and give it the same group.