Overview
The Label component (SpriteText) provides basic single-line or multi-line text display. Text entered into a SpriteText can be colored in-editor either using its Color setting, or by adding color tags to the text entered via the editor. Color tags follow the following hexadecimal format: [#RRGGBBAA] (ex: [#FF000080] is bright red with 50% transparency) or [#RRGGBB] (ex: [#FF0000] is bright red opaque) As you can see, the alpha component is optional, and if omitted, opaque is assumed. An example use of this would be: "Roses are [#FF0000]red, violets are [#00FF00]blue." The above string would set "Roses are" to whatever color is specified in the SpriteText's Color field. "red, violates are" would be tinted red, and "blue." will be tinted blue. Note the use of the term "tinted" here. The color specified in the color tag is actually multiplied by the main "Color" setting. In addition, this color tints the color of the actual font texture (see the important note below). So for example, for the color tag for red to result in pure red, both the font texture color must be white, as well as the main Color setting. You can also add color in-line with your text through code by simply "adding" Colors to the string: // Outputs a string where the last word "red" is colored red
Note that text that precedes a color tag is colored by the "global" color setting specified in the SpriteText's color field. All text text follows a color tag will be colored by that tag until another tag is encountered.
An important note on colors: It is important to note that the method used for coloring is to tint characters using vertex colors. As such, for accurate color reproduction, your font needs to have white letters. It can then be colored to any desired color from there. If your font is black, for example, it cannot be made any shade lighter than that.
Alignment and Anchoring There may sometimes be confusion as to the role played by the Alignment and Anchor settings. These settings behave identically to those of Unity's TextMesh (3D Text), so if you are familiar with those, you should have no difficulty. Basically, whenever text is entered into a SpriteText, an "area" of text begins to grow as the text is filled in. If the anchor is set, for example, to Upper_Left, then the upper-left corner of this "area" will be aligned with the SpriteText's GameObject's center point. This is the function of the Anchor setting. When there is only a single line of text, depending on your anchor settings, it is difficult to notice any effect of the Alignment setting, as the "area" of a single line of text is fitted tightly to its edges in any case. Where you will begin to see a difference is when the text has multiple lines. Basic Setup To get up and running with a SpriteText, you just need to assign a font definition (TextAsset) to its Font field, and a material to its Mesh Renderer. Now just enter some text in the Text field. To learn more about creating the necessary font definition file and font atlas, see Creating Fonts. |
Class |
Interactivity
You can set/retrieve the textual contents of the control by accessing its .Text property from script. You can set the "global" color of the text using its .SetColor() method. NOTE: The global color will be overridden by any color tags in the text (assuming parsing of color tags is enabled). |
Control-specific Properties
|