unity3d html 富文本框,富文本

自动布局

UI 参考

富文本

UI 元素和文本网格的文本可以包含多种字体样式和大小。UI 系统和旧版 GUI 系统都支持富文本。Text、GUIStyle、GUIText 和 TextMesh 类都具有 Rich Text 设置,此设置会指示 Unity 在文本中查找标记标签。Debug.Log 函数也可使用这些标记标签来增强代码中的错误报告。标签不会显示,但会指示要应用于文本的样式更改。

标记格式

该标记系统受 HTML 的启发,但并不打算与标准 HTML 严格兼容。基本思想是可以将文本的一部分包含在一对匹配标签内:

We are not amused

如示例所示,标签就是“尖括号”字符 < 和 > 内的文本片段。标签内的文本表示标签的名称(在本示例中就是 b)。请注意,该部分末尾的标签与开头的标签具有相同名称,但添加了斜杠 / 字符。标签不会直接显示给用户,而是用于说明其包裹的文本的样式。上例中使用的 b 标签将粗体应用于单词“not”,因此文本将在屏幕上显示为:

We are not amused

标记的文本部分(包括将其包裹的标签)称为元素。

嵌套的元素

通过将一个元素“嵌套”在另一个元素中,可以将多个样式应用于文本的一部分

We are definitely not amused

i 标签表示应用斜体样式,因此将在屏幕上显示为

We are definitely not amused

请注意结束标签的顺序与起始标签的顺序相反。为了更清楚说明原因,现在让内部标签不必跨越最外层元素的整个文本

We are absolutely definitely not amused

得到的结果为

We are absolutely definitely not amused

标签参数

有些标签对文本具有简单的“全有或全无”(all-or-nothing) 效果,但其他标签可能允许变化。例如,color 标签需要知道要应用的颜色。应使用参数将此类信息添加到标签中:

We are green with envy

请注意,结束标签不包含参数值。可选择将值用引号引起来,但这不是必需的。

支持的标签

以下列表描述了 Unity 支持的所有样式标签。

Tag

Description

Example

Notes

b

Renders the text in boldface.

We are not amused.

i

Renders the text in italics.

We are usually not amused.

size

Sets the size of the text according to the parameter value, given in pixels.

We are largely unaffected.

Although this tag is available for Debug.Log, you will find that the line spacing in the window bar and Console looks strange if the size is set too large.

color

Sets the color of the text according to the parameter value. The color can be specified in the traditional HTML format. #rrggbbaa …where the letters correspond to pairs of hexadecimal digits denoting the red, green, blue and alpha (transparency) values for the color. For example, cyan at full opacity would be specified by

Another option is to use the name of the color. This is easier to understand but naturally, the range of colors is limited and full opacity is always assumed. … The available color names are given in the table below.

颜色名称

十六进制值

样本

aqua(等同于 cyan)

#00ffffff

0a07177e17cb4793f5326a0f85ebe752.png

black

#000000ff

ed6dd33a75305339631cae5ffae21d33.png

blue

#0000ffff

c271125067bf00bdce67638c5abcdb16.png

brown

#a52a2aff

c041afa9f64571a362e70fb9f89d5bff.png

cyan(等同于 aqua)

#00ffffff

0a07177e17cb4793f5326a0f85ebe752.png

darkblue

#0000a0ff

97acde68668842ed5b108f58c64f5c11.png

fuchsia(等同于 magenta)

#ff00ffff

0f7356411668284e20a2e87226e470f1.png

green

#008000ff

734e8c286582c153703e877f77e69c14.png

grey

#808080ff

8ffbfe311c2e330e02ba5ac7da69e278.png

lightblue

#add8e6ff

6758d24695601b993bd2f7ee6cf1169f.png

lime

#00ff00ff

114e9ea161b33efb70b849a10c32a751.png

magenta(等同于 fuchsia)

#ff00ffff

0f7356411668284e20a2e87226e470f1.png

maroon

#800000ff

d4b206040009fa3b48edcaf7d9eeaf6d.png

navy

#000080ff

9129bb39d83fee65ebb84b020bcaacdb.png

olive

#808000ff

e8d5c045b300c85a2e87681aa0134317.png

orange

#ffa500ff

a0f18ff38380e390122da33da9a3d0b7.png

purple

#800080ff

82cb552c9ca105f38079e7c7bbfa0330.png

red

#ff0000ff

bea179b981753b9b14f90205ae8511bc.png

silver

#c0c0c0ff

aed37807d7e511f8d0213ca914a1a3f9.png

teal

#008080ff

78d28546192b9e46624ef6322c2261c2.png

white

#ffffffff

657176e389359ef90fe7693053f19806.png

yellow

#ffff00ff

a422616c68f7560c4ea07b34bb2c08bc.png

material

这仅对文本网格有用,使用参数指定的材质渲染文本部分。值为 Inspector 显示的文本网格材质数组的索引。

We are texturally amused

quad

这仅对文本网格有用,渲染与文本内联的图像。采用指定图像材质的参数、图像高度参数(以像素为单位)以及另外四个表示待显示图像的矩形区域的参数。与其他标签不同,quad 不会包裹一段文本,因此没有结束标签;斜杠字符放在初始标签的末尾,表示“自动关闭”。

这将选择渲染器材质数组中位置的材质,并将图像的高度设置为 20 像素。图像的矩形区域由 x、y、宽度和高度值决定,这些值全部表示为纹理的未缩放宽度和高度的一定比例。

Editor GUI

默认情况下,Editor GUI 系统中已禁用富文本,但可以使用自定义 GUIStyle 显式启用富文本。应将 richText 属性设置为 true,并将样式传递给相关的 GUI 函数:

GUIStyle style = new GUIStyle ();

style.richText = true;

GUILayout.Label("Some RICH text",style);

自动布局

UI 参考

Unity3D UGUI 专用文字特效插件 Text Effects 1.15 UI Text Effects are a set of effects for the standard Unity UI (uGUI) Text. - All script and shader sources included! - Extremely easy to use - just choose the effect from the component menu, and it's applied. - Add fancy titles, custom text appearance, mix multiple effects. - Rich Text support. - Mobile platform support. 12 extremely valuable effects: - Better Outline: a more continuous outline than the standard one. - Gradient Color: global/local, vertical/horizontal, override/additive/multiply. - Depth Effect: add thickness to text. - Soft Shadow: blurry shadow. - Outer Bevel: add outer lit and shaded edges. - Skew Effect: add horizontal+vertical transformations and perspective. - Curve Effect: bend or distort text vertically. - Character Spacing: increase or decrease the distance between individual characters. - Limit Visible Characters: hide characters, make a typewriter. - Overlay Texture: add an image overlay, local/global, override/additive/multiply. - Inner Bevel: add lit and shaded edges inside the characters, override/additive/multiply (only "override" on SM2 level GPUs). - Inner Outline: add outline inside the characters, override/additive/multiply. - With this package, you can finally echo effects from Photoshop or Word, while still using the standard Unity UI Text. - Suggestions for new effects are very welcome. The newly made effects will be added to the package. 仅供学习交流使用,如有侵权请告知删除。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值