Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

I wrote an "OverlapLayoutGroup" that facilitates creating tab pages.

Discussion in 'UGUI & TextMesh Pro' started by NirielNabokov, Jan 8, 2015.

  1. NirielNabokov

    NirielNabokov

    Joined:
    Dec 22, 2014
    Posts:
    9
    I was implementing a system of tabs (see attached pictures) and wanted to benefit from the layout system. Tab buttons control tab pages. I wanted that all the tab pages occupy the same space, and they they all took the size of the largest of them. I could not achieve that effect with the existing LayoutGroups and LayoutElement of Unity, so I looked at their source code to implement my own.

    Code of my OverlapLayoutGroup: http://pastebin.com/zhaUgnd5

    On pictures 1 and 2, you see that all the tab pages have the size of the largest one.
    Having tab pages overlapping in the editor (picture 3) makes editing difficult. I just disable the component (picture 4) in the editor and enable it at run time, this lets me design my GUI easily.

    Note 1: I have not integrated this script to the editor, it will not appear under GameObject/UI. I just drag and drop it from my asset folder. It seems that doing so is just a matter of adding "
    [AddComponentMenu("Layout/Overlap Layout Group", 150)]" before the class name, but I do not know what to put in place of the number 150.

    Note 2: the script does not care about the flexibility attributes of the children yet, it forces them to fill all the space even if they do not want to ; a behavior similar to that of a Horizontal or VerticalLayoutGroup with ChildForceExpand set to true. This is sufficient to my needs, I hope you will find it useful at well!
     

    Attached Files:

  2. neitron

    neitron

    Joined:
    Sep 14, 2014
    Posts:
    14
    I like your work, but where did you find info about layout group behaviour and API, because Unity official API says only something like "Called by the layout system." ?