void CreateRow() { //Debug.Log ("Create the text for this page"); SentenceRow sentenceRowClone = Instantiate(sentenceRowPrefab, sentenceRowPrefab.transform.parent); sentenceRowClone.gameObject.SetActive(true); rows.Add(sentenceRowClone); }
public void AddText(WordGroupObject wordGroup) { //Debug.Log ("78THOUSAND"); string[] words = wordGroup.text.Split(' '); narrator = words [0]; for (int i = 0; i < words.Length; i++) { string word = words [i]; SentenceRow currentRow = rows [rowIndex]; WordText newText = currentRow.AddText(word); newText.text.color = NormalColor; //wordClone.GetComponent<Button> ().color.normalColor = Color.cyan; //To enforce the layout to rebuild, which makes the horizontal layoutgroup resize LayoutRebuilder.ForceRebuildLayoutImmediate(rt); float myWidth = rt.rect.width - layoutGroup.padding.horizontal; //We add a text, check if the width is fitting. if (currentRow.rt.rect.width + newText.rt.rect.width >= myWidth) { CreateRow(); currentRow.PopText(); rowIndex++; //Safety check in case of really long words if (newText.rt.rect.width < myWidth) { //go a word back i -= 1; } else { Debug.LogWarningFormat("The word {0} does not fit in the SentenceRowContainer! It will be skipped.", word); } } else { //We set the wordGroup of each textfield so we can highlight them alltogether newText.wordGroup = wordGroup; texts.Add(newText); } } }