private void BuildMenuText() { text_field.text = ""; for (int i = 0; i < menu_options.Count; i++) { if (i == menu_options.Count - 1) { text_field.text += ui_manager.ReplaceTextCode(MENU_OPTIONS[(int)menu_options[i]]); } else { text_field.text += ui_manager.ReplaceTextCode(MENU_OPTIONS[(int)menu_options[i]]) + '\n'; } } float text_height = text_field.preferredHeight; }
private string[] BreakUpMessage() { List <string> lines = new List <string>(); // Split message by words string[] words = message.Split(' '); int num_words = words.Length; // Get size of a space in current context text_field.text = " "; float space_width = text_field.preferredWidth; text_field.text = null; // Build lines word by word string current_line = ""; float current_line_width = 0f; //Stack<string> current_markup = new Stack<string>(); for (int i = 0; i < num_words; i++) { string word = words[i]; // TODO: Check for line breaks, tabs, pauses, etc. // Check for replacement codes {CODE} such as player name: {PN} word = ui_manager.ReplaceTextCode(word); // Get length of this word text_field.text = word; float word_width = text_field.preferredWidth + space_width; text_field.text = null; // Add word to current line if it fits if (current_line_width + word_width <= text_field_width) { current_line += word + " "; current_line_width += word_width; } // Otherwise add the finished line and start a new one else { lines.Add(current_line); current_line = word + " "; current_line_width = word_width; } } // Add final line and return all lines lines.Add(current_line); return(lines.ToArray()); }