Version: 2019.2
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. Aunque esta etiqueta está disponible para debug.log, usted encontrará que el interlineado en la barra de la ventana y la consola tienen un aspecto extraño, si el tamaño es demasiado grande.
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 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 Esto es solamente útil para meshes de texto y renderiza una imagen enlinea con texto. Toma parámetros que especifican el material a usar para la imagen, la altura de la imagen en píxeles, y otros cuatro que denotan un área rectangular de la imagen para mostrar. A diferencia de las otras etiquetas, quad no rodea una parte del texto y por lo tanto no hay ninguna etiqueta final - el carácter de barra se coloca al final de la etiqueta inicial para indicar que se trata de “cierre automático”. <quad material=1 size=20 x=0.1 y=0.1 width=0.5 height=0.5> Esto selecciona el material en posición en la matriz del material renderizado y establece la altura de la imagen a 20 píxeles. El área rectangular de imagen comienza en los valores dados x,y, del ancho y altura, que son todos dados como un fracción de la anchura sin escala, y la altura de la textura.

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