Author Topic: Advice with custom list generator  (Read 4334 times)

kruncher

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Advice with custom list generator
« 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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Advice with custom list generator
« Reply #1 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.

kruncher

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: Advice with custom list generator
« Reply #2 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.