使用Unity中UGUI的人都会有一个问题,在Text中显示中文文字是Text文本会莫名其妙的出现换行的问题
Text 在unity中的一段文字
不做处理是以下的显示效果
当对文字进行处理之后显示就不会出现换行的问题了。
Text只会对英文空格进行自动换行,当将英文空格换成中文空格(\u3000)时文本就不会被换行,而且也能实现一些文本设置如:首行缩进等.
private void settext()
{
//获取Text的文本内容
string temp_content = mText.text;
string temp_indent = "";
//首行缩进的字符数
int m_Text_indent =2;
for (int i = 0; i < m_Text_indent; i++)
{
temp_indent = string.Format("{0}{1}", temp_indent, "\u3000");
}
temp_content = string.Format("{0}{1}", temp_indent, text);
//处理空格
if (m_IsSpace)
{
temp_content = temp_content.Replace(" ", "\u3000");
}
//首行缩进替换
temp_content = temp_content.Replace("\n", "\n" + temp_indent);
//重新设置Text文字
mText.text = temp_content;
}