Skip to content

JSILabel

MOARdV edited this page May 12, 2016 · 13 revisions

What it Does

This module displays a variable and/or text using Unity's TextMesh text rendering system. This module can display text, and it can use formatting strings and variables. For non-changing text (see oneShot below), it has low overhead. It permits you to use all the variable processing features of RasterPropMonitor while displaying the text in a similar way to the stock InternalSpeed module.

When to Use It

Use this module to display simple text, such as labels on controls. It's useful in places where a little bit of configurable text is needed, but going through all of the effort of a full RasterPropMonitor is not justifiable (eg, adding a label to a switch). JSILabel has more configuration options than JSIVariableLabel, but it does not allow inline text color values (eg, [#ff0000]).

How to Use It

This module is appropriate to use when you need to display a variable or text, but a full RasterPropMonitor is overkill. Labels on props are one good use.

Configuration:

  • alignment -- An optional string to control how multiple lines of text are aligned. Valid values are Left, Center, and Right. If alignment is omitted, it defaults to Left.
  • anchor -- An optional string to control how the text is placed relative to transformName. Valid values are LowerCenter, LowerLeft, LowerRight, MiddleCenter, MiddleLeft, MiddleRight, UpperCenter, UpperLeft, and UpperRight.
  • fontName -- The name of a font that's expected to be installed on the user's computer. If the requested font is not available, Arial is used as a fallback (since Unity guarantees Arial or an equivalent typeface is available).
  • fontQuality -- An integer that controls the quality of the rendered font. By default, it is 32. Use higher values for large text that looks blurry using default settings.
  • fontSize -- The size of the font. Defaults to 0.008 -- 1 means that the font character height occupies one space unit vertically, so by default you get fonts as large as a meter.
  • lineSpacing -- Used to scale line-to-line spacing. By default, it is 1. Smaller numbers place the lines closer together.
  • labelText -- The text to be printed and processed. Obeys the same rules as the text given directly in prop.cfg, i.e. { and } must be replaced with <= and => respectively. A quote (") can be used at the beginning of the text to allow it to prevent leading whitespace from being removed. The quote character is removed before the string is displayed (if you want a quotation mark at the beginning of the text, use two in a row, eg "").
  • negativeColor -- An optional RGBA sequence (eg. '255, 255, 0, 255') used for coloring the text. See color changing mode below.
  • oneshot -- A boolean, defaults to false. When it is true, label text will only be processed once on IVA creation and will no longer refresh -- useful for action button labels. A label that contains no variable processing syntax is automatically oneshot.
  • refreshRate -- How often the text will be recomputed.
  • transformName -- The name of the transform the text will be attached to. The transform needs to be a Unity collider oriented Z- away from the surface the text is to be visible on and X+ to the right.
  • transformOffset -- the optional X and Y displacement of the transform transformName. This can be used for props that were not specifically set up to use JSILabel to move the anchor to a better location (such as centering text).
  • variableName -- An optional name of one of the defined variables. This variable is evaluated for color changing mode (see below).
  • zeroColor -- An optional RGBA sequence (eg. '255, 255, 0, 255') used for coloring the text. When used by itself, it sets the color of the text. See color changing mode below.

Color Change Mode

By default, a JSILabel's text is white. To change the text color, provide a value in zeroColor (even if the color change mode is otherwise not used).

Text color can also be changed based on a variable query. In this mode, any time the variable identified with variableName changes, the color of the text will be updated based on whether the variable is positive, negative, or zero.

Color change mode is enabled by including all four of variableName, positiveColor, negativeColor, and zeroColor. In use, it works the same as the C# text formatting option for numeric variables: if the result of variableName is positive, the text color is set to positiveColor. For negative values, the text color is set to negativeColor, and for zero, zeroColor.

When using callback mode, refreshRate is ignored (unless the text has variables to process, as well). Instead, the text color is change immediately when RasterPropMonitor detects the change.

Clone this wiki locally