Panel UI organisation
Hi guys,
I'm looking on creating a panel for a Secret Word game, I have in mind how I would like to have it in mind but cannot get to actually implement it in unity:
Here is my idea:
Secret words is selected randomly and SecretWord Panel should fit the content '?' and be horizontally center in the first row of the MainPanel.
Row1 to Row3 are dynamic, as Spanish keyboard has additional letters 'Ñ' as well as other languages, in comparison with English, Spanish would have an additional letter in row2.
This is my configuration for the MainPanel
And this is my configuration for one of the letter rows:
As well as the letters are prefab buttons that are created dynamically within a script when the user select a random secret word from a language with the following code:
void AddKeyboardRow(List row, int height, Transform rowPanel) {
float panelWidth = rowPanel.GetComponent<RectTransform> ().rect.width;
float panelHeight = rowPanel.GetComponent<RectTransform> ().rect.height;
int i = 0;
foreach(string letter in row) {
var button = (GameObject)Instantiate (buttonPrefab);
var textComponent = button.GetComponentInChildren<Text> ();
textComponent.text = letter;
button.GetComponent<Button> ().onClick.AddListener (
() => {LetterSelected(letter);}
);
button.transform.SetParent(rowPanel, false);
button.transform.localPosition = new Vector3(0,0,1);
i++;
}
LayoutRebuilder.ForceRebuildLayoutImmediate (rowPanel.GetComponent<RectTransform> ());
}
Thanks a lot for your help!