Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: kruncher on January 06, 2014, 01:36:09 PM

Title: Advice with custom list generator
Post by: kruncher on January 06, 2014, 01:36:09 PM
I need to create a custom generator which produces a listing of items by instantiating various template prefabs. Each template will be some sort of widget container.

Instantiated widgets should be automatically anchored to the left and right of the listing generator. The items need to be stacked in the same order that they are generated. The item templates are of varying heights.

What is the best way to go about this?
Title: Re: Advice with custom list generator
Post by: ArenMook on January 06, 2014, 05:24:18 PM
Create a single row with both left and right elements. Save it as a prefab. Instantiate it one row at a time, populating its content as needed. You will still want to do widget.SetAnchor if you want them to be anchored to a parent that's not a part of the prefab.
Title: Re: Advice with custom list generator
Post by: kruncher on January 06, 2014, 08:43:17 PM
Thanks for the advice, I have this working lovely :D

`widget.SetAnchor` wasn't quite specific enough, so I went with the following instead:
  1. widget.leftAnchor.target = cachedTransform;
  2. widget.leftAnchor.Set(0f, 0f);
  3. widget.rightAnchor.target = cachedTransform;
  4. widget.rightAnchor.Set(1f, 0f);
  5.  
  6. widget.ResetAnchors();
  7. widget.UpdateAnchors();
  8.