Unity 多个Text显示一段内容,字数分割
List<string> SplitString(Text[] texts, string value)
{
List<string> listStr = new List<string>();
string leftValue = value;
for (int i = 0; i < texts.Length; i++)
{
string tempstr = "";
var generator = new TextGenerator();//文本生成器
var rect = texts[i].GetComponent<RectTransform>().rect;
var setting = texts[i].GetGenerationSettings(rect.size);//文本设置
generator.Populate(leftValue, setting);
int charactreCountVisible = generator.characterCount;//可见字数index
if (string.IsNullOrEmpty(leftValue))
break;
if (leftValue.Length > charactreCountVisible)
{
tempstr = leftValue.Substring(0, charactreCountVisible);
leftValue = leftValue.Substring(charactreCountVisible, leftValue.Length - charactreCountVisible);
}
else
{
tempstr = leftValue;
leftValue="";
}
listStr.Add(tempstr);
}
return listStr;
}