Wednesday, June 22, 2022

Rich Text


Rich Text


Text and text meshes in GUI elements can contain multiple font styles and sizes. 
Rich text is supported by both the UI system and the legacy GUI system. 
The Text, GUIStyle, GUIText and TextMesh classes have Rich Text settings, which instruct Unity to look for markup tags among text. You can also use this markup tag in the Debug.Log function to update the error report in your code. This tag is not displayed, but it is reflected in the text, indicating a style change.
Markup format

The markup system takes its hints from HTML, but it is not intended to conform strictly to standard HTML. The basic idea is, that part of the text is closed by a pair of matching tags :-

We are <b>not</b> amused

As the example shows, tags are text enclosed in “parentheses” signs, < and >. The text inside the tag represents the name (in this case simply b ). Note that the tag at the end of the section has the same name as the beginning, but is used with a slash (/) sign. Tags are not directly visible to the user, but are interpreted as hidden text style directives. Because the b tag in the example above applies the word “not” in bold type, the text will appear on the screen as follows:-

We are not amuse

Sections of text markup (including enclosing tags) are referenced as elements .
Nested elements

You can apply more than one element to text by “nesting” one element to another.

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

Because the italic style is applied by the i tag, the screen will look like this:

We are ** definitely not** amused

Note that the order of the end tags is reversed from that of the start tags. The reason becomes clear when you consider that the inner tag's scope doesn't include all of the outer elements.

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

according to the following

We are absolutely definitely not amused
tag parameters

Some tags have a simple have/no effect, on the text, but otherwise might change. For example, the color tag needs to know which color to apply. This information is added to the tag by the use of parameters .

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

Note that the end tag does not contain parameter values. As an option, the value is ? You can wrap it with a symbol, but it's not required.
Supported tags

The following list shows all tags supported by Unity.
TagexplanationExampleNotes
bRender text bold.   We are <b>not</b> amused.
It'sRender text in italics.   We are <i>usually</i> not amused.
sizeSets the text size in pixels based on the parameter value.   We are <size=50>largely</size> unaffected.This tag is also valid in Debug.Log, but if you make it too large, the window bar and console line will be weird.
color nameSet the text color according to the parameter value. Colors can be described in a typical HTML format.    #rrggbbaa … where the string represents the red, green, blue, and alpha (transparent) values ​​of the color, corresponding to the number of digits in the hexadecimal number. For example, a fully opaque cyan would be specified as   <color=#00ffffff>…Another option is to use color names. This is simple to understand, but it has a limited range of colors and is always completely opaque.    <color=cyan>…  Available color names are listed in the table below.

color name         Hexadecimal              color swatchaqua  
black                 #000000ff                 
blue                   #0000ffff                   
brown               #a52a2aff                  
cyan                  #00ffffff                     
apua                  #00ffffff                     
dark blue           #0000a0ff                 
fuchsia               #ff00ffff                     
magenta             #ff00ffff                     
green                 #008000ff                 
gray                   #808080ff                 
light blue            #add8e6ff                  
lime                   #00ff00ff                    
maroon             #800000ff                   
navy                 #000080ff                   
olive                 #808000ff                   
orange              #ffa500ff                     
purple               #800080ff                  
red                    #ff0000ff                    
silver                 #c0c0c0ff                   
teal                    #008080ff                  
white                 #ffffffff                        
yellow               #ffff00ff