- Home /
Help w/GUILayout Please
Hi,
I have a dictionary like this: Dictionary UsersInMatch
I need to display the data as:
Match#1
User_A
User_B
Match#2
User_C
User_D
Match#3
User_E
User_F
Like that, so here is what I Have tried, but I cannot seem to put two and two together.
Code: int matchNumber = 1;
GUILayout.BeginArea(new Rect(Screen.width-220,300,220,100));
GUILayout.BeginVertical("",s);
foreach (KeyValuePair<string, string[]> Entry in UsersInMatch)
{
GUILayout.Label("Match #" + matchNumber.ToString(), s);
GUILayout.Space(10);
matchNumber++;
}
GUILayout.EndVertical();
GUILayout.EndArea();
The vertical space works. I see the following:
Match #1
Match #2
Match #3
So here is what I would write as the inner iteration scheme to iterate through the values of the string[]:
Code:
GUILayout.BeginArea(new Rect(Screen.width-220, 330, 220, 100));
GUILayout.BeginVertical("", s);
foreach (string name in Entry.Value)
{
GUILayout.Label(name, s);
GUILayout.Space(10);
}
GUILayout.EndVertical();
GUILayout.EndArea();
Finally, putting two and two together we have:
Code:
private void displayUsersInMatch() {
int matchNumber = 1;
GUILayout.BeginArea(new Rect(Screen.width-220, 300, 220, 100));
GUILayout.BeginVertical("", s);
foreach (KeyValuePair<string, string[]> Entry in UsersInMatch)
{
GUILayout.Label("Match #" + matchNumber.ToString(), s);
GUILayout.Space(10);
GUILayout.BeginArea(new Rect(Screen.width-220,330,220,100));
GUILayout.BeginVertical("", s);
foreach (string name in Entry.Value)
{
GUILayout.Label(name, s);
}
GUILayout.EndVertical();
GUILayout.EndArea();
matchNumber++;
}
GUILayout.EndVertical();
GUILayout.EndArea();
}
And I don't see anything in between the Match# headings. If someone could shine some light on this it would really make my day!
Answer by syclamoth · Dec 03, 2011 at 05:26 AM
Basically, GUILayout.BeginArea cannot be nested. You should get rid of the second one, since it's screwing everything up. You need to use combinations of BeginHorizontal, BeginVertical, and Space(some disntace) to emulate the same behaviour.