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;
}
}