Version: 2019.1
Diseño Automático
Referencia UI

Rich Text

El texto para los elementos UI y text meshes pueden ser incorporados por múltiples estilos de fuente y tamaños. El Rich text es soportado para ambos el sistema UY y el viejo sistema GUI legacy. Las clases Text, GUIStyle, GUIText y TextMesh tienen unas configuraciones Rich Text que instruyen a Unity para mirar por las etiquetas de markup dentro del texto. La función Debug.Log puede también utilizar estas etiquetas markup para aumentar los reportes de error de código. Las etiquetas no son mostrados pero indican cambios en el estilo par ser aplicados al texto.

Markup format

El sistema de marcado está inspirado por HTML pero no está intencionado en ser estrictamente compatible con HTML estándar. La idea básica es que una sección del texto puede ser encerrado a dentro de un par de etiquetas de marcado:-

We are <b>not<b> amused.

As the example shows, the tags are just pieces of text inside the “angle bracket” characters, < and >.

You place the opening tag at the beginning of the section. The text inside the tag denotes its name (which in this case is just b).

You place another tag at the end of the section. This is the closing tag. It has the same name as the opening tag, but the name is prefixed with a slash / character. Every opening tag must have a corresponding closing tag. If you don’t close an opening tag, it is rendered as regular text.

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 appears ons creen as:-

We are not amused

Una sección marcada de texto (incluyendo las etiquetas que la encierran) es referida como un element.

Nested elements

Es posible aplicar más de un estilo a una sección de texto al “nesting” un elemento adentro de otro

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

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

We are definitely not amused

Note the ordering of the closing tags, which is in reverse to that of the opening 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

que da

We are absolutely definitely not amused

Tag parameters

Algunas etiquetas tienen un efecto simple de todo-o-nada en el texto pero otras podrían permitir variaciones. Por ejemplo, la etiqueta color necesita saber qué color aplicar. Información como esta es agregada a las etiquetas mediante el uso de parameters:-

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

Which produces this result:

Tenga en cuenta que la etiqueta de finalización no incluye el valor del parámetro. Opcionalmente, el valor puede ser rodeado por signos de interrogación pero esto no es requerido.

Tag parameters cannot include blank spaces. For example:

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

does not work because of the spaces to either side of the = character.

Supported tags

La siguiente lista describe todas las etiquetas de estilo soportadas por Unity.

Tag Description Example Notes
b Renderiza el texto en negrilla. We are <b>not</b> amused.
i Renderiza el texto en itálico. We are <i>usually</i> not amused.
size Establece el tamaño del texto de acuerdo al valor del parámetro, dado en píxeles. 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 you set the size too large.
color Sets the color of the text according to the parameter value. You can specify the color in HTML format, as in #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 is specified by color=#00ffffff

You can specify hexadecimal values in uppercase or lowercase; #FF0000 is equivalent to #ff0000.
We are <color=#ff0000ff>colorfully</color> amused 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>some text</color> The available color names are given in the table below.
material Esto es solamente útil para meshes de texto y renderiza una sección del texto con un material especificado por el parámetro. El valor es un índice a la matriz del mesh de texto de los materias como es mostrado por el inspector. We are <material=2>texturally</material> amused
quad Renders an image inline with the text. This is only useful for text meshes. 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”. <quad material=1 size=20 x=0.1 y=0.1 width=0.5 height=0.5> This selects the material at the position in the renderer’s material array and sets the height of the image to 20 pixels. The rectangular area of the image starts at the position 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.

Supported colors

The following table lists colors for which you can use a name instead of a hexadecimal tag in the <color> rich text tag.

Nombre del Color Valor Hex Swatch
aqua (el mismo que el cian(cyan)) #00ffffff
negro #000000ff
azul #0000ffff
marrón #a52a2aff
cian(cyan) (el mismo que el aqua) #00ffffff
azul oscuro #0000a0ff
fucsia(fuchsia) (el mismo que magenta) #ff00ffff
verde #008000ff
gris #808080ff
azul claro #add8e6ff
limón #00ff00ff
magenta (el mismo que fuchsia) #ff00ffff
granate #800000ff
azul marino #000080ff
oliva #808000ff
naranja #ffa500ff
morado #800080ff
rojo #ff0000ff
plateado #c0c0c0ff
verde azulado #008080ff
blanco #ffffffff
amarillo #ffff00ff

Editor GUI

Rich text is disabled by default in the Editor GUI system but it can be enabled explicitly using a custom GUIStyle. The richText property should be set to true and the style passed to the GUI function in question:-

GUIStyle style = new GUIStyle ();
style.richText = true;
GUILayout.Label("<size=30>Some <color=yellow>RICH</color> text</size>",style)
Diseño Automático
Referencia UI