Search Unity

Generating List (conversion from old GUI)

Discussion in 'UGUI & TextMesh Pro' started by ManAmazin, Sep 5, 2014.

  1. ManAmazin

    ManAmazin

    Joined:
    Aug 7, 2013
    Posts:
    246
    Hey guys just looking for some clarification and direction

    i have quite a few list in my game, ive seen something about having to use instantiation to generate in new UI is this correct?

    for instance in old GUI:

    Code (CSharp):
    1. foreach(Gun gn in myGunList)
    2. {
    3.      GUILayout.Label(gn.GunName);
    4. }

    and your done

    etc same goes for the buttons ..you get the picture....

    is instantiating the only way to do this currently in the new GUI?
     
  2. Kylotan

    Kylotan

    Joined:
    Feb 17, 2011
    Posts:
    212
    It's not the only way, but it's probably the most practical one, as it lets you have more control over the items before you add them. The way I approach it is to have a panel with a VerticalLayoutGroup, and then I Instantiate a prefab for each row. I found there were several gotchas involved too, such as needing to set LayoutElements on the items in the row to make sure they didn't get compressed down to zero height, moving the panel pivot to the top to ensure new items got added to the bottom (rather than moving the panel up to accommodate them), etc.
     
  3. ManAmazin

    ManAmazin

    Joined:
    Aug 7, 2013
    Posts:
    246

    Thanks for the response ill play with it and repot back im sure i wont get it right the first..havent even played with vertical layout groups