Unity3d学习笔记 RichText

富文本 Rich Text

Date:2013-08-02 04:32
The text for GUI elements and text meshes can incorporate multiple font styles and sizes. The GUIStyle, GUIText and TextMesh classes have a Rich Text setting which instructs Unity to look for markup tags within the text. The Debug.Log function can also use these markup tags to enhance error reports from code. The tags are not displayed but indicate style changes to be applied to the text.

这种文本用于GUI元素和文本网格可以结合多种字体类型和大小。 GUIStyle, GUIText 和 TextMesh类都有富文本设置,能指示unity寻找文本内含有的标记标签。Dubug.Log也可以用这些标记标签来增强代码报告错误的能力。这些标签不显示,而是显示应用到文本的风格变化。

Markup format 标记格式

The markup system is inspired by HTML but isn’t intended to be strictly compatible with standard HTML. The basic idea is that a section of text can be enclosed inside a pair of matching tags:-

该标记系统的灵感来源于HTML但不打算要严格兼容标准的HTML。其基本思路是,一对匹配的标签里面可以包含一部分文字:

We are <b>not</b> amused  

As the example shows, the tags are just pieces of text inside the “angle bracket” characters, < and >. The text inside the tag denotes its name (which in this case is just b). Note that the tag at the end of the section has the same name as the one at the start but with the slash / character added. The tags are not displayed to the user directly but are interpreted as instructions for styling the text they enclose. The b tag used in the example above applies boldface to the word “not”, so the text will appear onscreen as:-

示例所示,标签只是“尖括号”和文本,< 和 >。标签内的文本表示的名字(在这个示例中就是b)注意:这个结尾部分的标签和开头那个名字一样但带有/符号。该标签不直接显示给用户但是诠释为它们扩起来的文字风格,即把not用b括起来,在例子中的b标签在单词“not”上应用粗体字,所以这个文本将会以如下形式出现:

We are not amused  

A marked up section of text (including the tags that enclose it) is referred to as an element.

已标记的文本块(包括标签括入的)被作为一个元素 如not

Nested elements 嵌套元素

It is possible to apply more than one style to a section of text by “nesting” one element inside another

通过嵌套一个元素到另一个元素里面来应用多种样式到一个文本块这个是可以的。

We are <b><i>definitely not</i></b> amused  

The i tag applies italic style, so this would be presented onscreen as

i标签应用斜体风格,所以将会以如下形式出现在屏幕上:

We are definitely not amused  

Note the ordering of the ending tags, which is in reverse to that of the starting tags. The reason for this is perhaps clearer when you consider that the inner tags need not span the whole text of the outermost element

注意结束标签的顺序,与起始标签顺序相反。这样做的原因是帮助你更清晰的考虑内部标签不必跨越整个文本的最外层元素。(标签不能交叉包含,只能一对标签包含另一对;而一对标签不能只包含另一对标签的一部分。)

We are <b>absolutely <i>definitely</i> not</b> amused  

which gives 显示为:

We are absolutely definitely not amused  

Tag parameters 标签参数

Some tags have a simple all-or-nothing effect on the text but others might allow for variations. For example, the color tag needs to know which color to apply. Information like this is added to tags by the use of parameters:-

某些标签有一些简单的效果,开始标签可以有一些参数,例如,color标记需要知道应用哪个颜色。像这个在开始标签应用参数:

We are <color=green>green</color> with envy  

Note that the ending tag doesn’t include the parameter value. Optionally, the value can be surrounded by quotation marks but this isn’t required.

注意结尾标签不包括参数素值。参数值可以由双引号包起来,但是这不是必需的。。

Supported tags 支持的标签

The following list describes all the styling tags supported by Unity.

下面的列表描述所有unity支持的标签样式。

b

Renders the text in boldface.

呈现粗体文本。

We are <b>not</b> amused  

i

Renders the text in italics.

呈现斜体文本。

We are <i>usually</i> not amused  

size 大小

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

根据给定的参数值,以像素为单位设定的文字大小。

We are <size=50>largely</size> 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.

虽然这个标签是Debug.Log看得到的,如果设置过大,你将会发现窗口栏和控制台的大小看起来很奇怪。

color 颜色

Sets the color of the text according to the parameter value. The color can be specified in the traditional HTML format

根据参数值设置文本颜色,颜色值可以用传统的HTML格式指定

#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

字母对应于对十六进位数字,表示红色,绿色,蓝色和alpha(透明度)值的颜色。例如,青色完全不透明:

<color=#00ffffff>...  

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.

另一种选择是使用的颜色名称。这是比较容易理解且自然,颜色的范围是有限的,总是假定完全不透明。

<color=cyan>...  

The available color names are given in the table below.

material 材质

This is only useful for text meshes and renders a section of text with a material specified by the parameter. The value is an index into the text mesh’s array of materials as shown by the inspector.

这仅用于文本网格并渲染具有材料参数所指定的一段文字。该值是文本网格显示在检视面板材质数组的索引。

We are <material=2>texturally</material> amused  

quad 嵌入

This is only useful for text meshes and renders an image inline with the text. It takes parameters that specify the material to use for the image, the image height in pixels, and a further four that denote a rectangular area of the image to display. Unlike the other tags, quad does not surround a piece of text and so there is no ending tag - the slash character is placed at the end of the initial tag to indicate that it is “self-closing”.

这仅用于文本网格和在文本内嵌图像。它的参数,material是用于图片,图片的高度以像素为单位,另外四个标参数表示一个用于显示图像的矩形区域。不像其他标签,quad不用环绕文字所以没有结束标签-斜杠符号放置在开始标签的结尾表明它是“自封闭的”。

<quad material=1 size=20 x=0.1 y=0.1 width=0.5 height=0.5 />  

This selects the material at position in the renderer’s material array and sets the height of the image to 20 pixels. The rectangular area of image starts at given by the x, y, width and height values, which are all given as a fraction of the unscaled width and height of the texture.

该行代码意思是材质的位置在渲染器的材质数组,同时设置图像高度为20像素。用于显示图像的矩形区域初始位置由X、Y、width和height的值提供,这些参数很适用于那些宽和高不成比例的图片。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值