1. 程式人生 > >Unity2017.1官方UGUI文檔翻譯——Rich Text

Unity2017.1官方UGUI文檔翻譯——Rich Text

ati array 理解 指導 調用 位置 rop 應用 ima

Rich Text

富文本

The text for UI elements and text meshes can incorporate multiple font styles and sizes. Rich text is supported both for the UI System and the legacy GUI system. The Text, 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.

UI元素和文本網格的文本可以包含多種字體樣式和大小。富文本同時支持UI系統和傳統的GUI系統。 Text,GUIStyle,GUIText和TextMesh類具有富文本設置,指示Unity在文本內查找標記標簽。 Debug.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)。 註意,這一段末尾的標簽與起始標簽名稱相同,但添加了斜杠/字符。 這些標簽不直接顯示給用戶,而是被解釋為指導他們所包括的文本的樣式。 上例中使用的b標簽將粗體字應用於單詞“not”,因此文本將在屏幕上顯示為:

We are not amused

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

被標記的一段文本(包括外面的標簽)被稱為元素。

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