UGUI Text(Label)

环境

Unity 5.3.6f1

关于Best Fit

如果勾选了 Best Fit ,当有大量的文本填充在Text上时,那么文字是不会自动换行的。

image

打字机效果

在github上已有现成的:https://github.com/synchrok/TypeText

效果类似NGUI的那种打字机效果。

BlinkIt (闪烁效果)

http://git.oschina.net/trlanfeng/TRGameUtils

主要是修改color

text.color = new Color(1, 1, 1, 0);

获取字体的高度

Text.preferredHeight,经测试:在设置大量字体之后,立刻获取此属性,获取的值并不是正确的,但在协程中等待当前帧结束获取的值,会比较接近。

测试文本:(用户协议),大概12KB,有12万个字符。

IEnumerator SetTextHeight()
    {
        yield return new WaitForEndOfFrame();
        var height = ContentText.preferredHeight + 300;
        //锚点使用stretch top ,-100是左右缩进50
        ContentText.rectTransform.sizeDelta = new Vector2(-100, height);
    }

富文本RichText

在属性面板上勾选RichText,就可以支持富文本了,富文本相关的属性如下:(文档要查找RichText而不是Text)

https://docs.unity3d.com/Manual/StyledText.html

原文地址:https://www.cnblogs.com/zhaoqingqing/p/6260108.html