private List <string> GetWordList(string source) { List <string> stringList = new List <string>(); StringBuilder stringBuilder = new StringBuilder(); char minValue = char.MinValue; for (int index = 0; index < source.Length; ++index) { char c1 = source[index]; char c2 = index >= source.Length - 1 ? minValue : source[index + 1]; char c3 = index <= 0 ? minValue : source[index - 1]; stringBuilder.Append(c1); bool flag1 = Hyphenation.ExistsLatin(c1) && Hyphenation.ExistsLatin(c3) && (Hyphenation.ExistsLatin(c2) && !Hyphenation.ExistsLatin(c3)); bool flag2 = !Hyphenation.ExistsLatin(c1) && Hyphenation.ExistsBehindHyphenation(c3); bool flag3 = !Hyphenation.ExistsLatin(c2) && !Hyphenation.ExistsAheadHyphenation(c2) && !Hyphenation.ExistsBehindHyphenation(c1); bool flag4 = index == source.Length - 1; if (flag1 || flag2 || (flag3 || flag4)) { stringList.Add(stringBuilder.ToString()); stringBuilder = new StringBuilder(); } } return(stringList); }
private string GetFormattedText(UnityEngine.UI.Text label, string msg) { if (msg.IsNullOrEmpty()) { return(string.Empty); } Rect rect = this.RectTransform.get_rect(); float width = ((Rect) ref rect).get_width(); float spaceWidth = this.GetSpaceWidth(label); label.set_horizontalOverflow((HorizontalWrapMode)1); StringBuilder stringBuilder = new StringBuilder(); int num1 = 0; float num2 = 0.0f; string str = "\n"; bool flag1 = Hyphenation.ExistsBehindHyphenation(msg[0]); bool flag2 = false; foreach (string word in this.GetWordList(msg)) { float num3 = this.GetTextWidth(label, word); num2 += width; if (word == str) { num2 = 0.0f + spaceWidth * 2f; ++num1; } else { if (word == string.Empty) { num2 += spaceWidth; } if (flag1) { if (!flag2) { flag2 = this.IsLineCountOver(label, num1 - 1); } if (flag2) { num3 = 0.0f; } if ((double)num2 > (double)width - (double)num3) { stringBuilder.Append(str); stringBuilder.Append(" "); num2 = this.GetTextWidth(label, word) + spaceWidth * 2f; ++num1; } } else if ((double)num2 > (double)width) { stringBuilder.Append(str); num2 = this.GetTextWidth(label, word); ++num1; } } stringBuilder.Append(word); } return(stringBuilder.ToString()); }