How To Programatically Add Nested Groups?

25 views
Skip to first unread message

rzeigler

unread,
Jan 26, 2011, 11:19:02 AM1/26/11
to bitverse-unity-gui
Is it possible to programatically add nested groups of different
types. Ideally, I would like to add nested horizontal groups within a
single vertical group (although the example posted below is nested
vertical groups within a horizontal group. In the code below, the
first for loop which just adds buttons programatically to a horizontal
group works correctly. However, the second block which adds buttons
into nested vertical groups does not display anything when the
horizontal group is made visible. I can verify that there are indeed
vertical groups and buttons appearing in the hierarchy inspector. What
am I doing incorrectly?
Regards,
Ryan Zeigler


public class ButtonController : MonoBehaviour {

BitHorizontalGroup _group;

void Start() {
BitWindow _window = this.GetComponent<BitWindow>();
BitToggle toggle =
_window.GetComponentInChildren<BitToggle>();
toggle.ValueChanged += ToggleClicked;
BitHorizontalGroup[] groups =
_window.GetComponentsInChildren<BitHorizontalGroup>();
foreach (BitHorizontalGroup candidate in groups) {
if (candidate.name == "Group") {
_group = candidate;
}
}
_group.Visible = (bool) toggle.Value;
for (int i = 0; i < 5; i++) {
BitButton button = _group.AddControl<BitButton>();
button.Visible = true;
button.Text = string.Format("Button i^10 = {0}",
Mathf.Pow(i, 10));
button.AutoSize = true;
button.MouseClick += AddOnButtonClicked;
}
/*
for (int i = 0; i < 5; i++) {
BitVerticalGroup _vgroup =
_group.AddControl<BitVerticalGroup>();
_vgroup.Visible = true;
for (int j = 0; j < 5; j++) {
BitButton button = _vgroup.AddControl<BitButton>();
button.Visible = true;
button.Text = string.Format("Button i^10 = {0}",
Mathf.Pow(i, 10));
button.AutoSize = true;
}
}
*/
}

void ToggleClicked(object sender, ValueChangedEventArgs args) {
_group.Visible = (bool) args.Value;
}
}

rzeigler

unread,
Jan 26, 2011, 11:30:03 AM1/26/11
to bitverse-unity-gui
I have resolved the issue. Apparently, I was not setting AutoSize to
true for the generated groups.
Reply all
Reply to author
Forward
0 new messages