Class RichText
Utility class for formatting rich text strings with color, size, and optional prefixes/suffixes for UI display. Provides both string-returning Format methods and zero-allocation AppendTo methods for StringBuilder use.
public static class RichText
- Inheritance
-
RichText
- Inherited Members
Methods
AppendTo(ref Utf16ValueStringBuilder, string, bool, string, string)
Appends a formatted string value with optional color, size, and line break directly to an existing string builder. Avoids intermediate string allocations when building composite tooltips.
public static void AppendTo(ref Utf16ValueStringBuilder sb, string value, bool appendLine = false, string hexColor = null, string size = null)
Parameters
sbUtf16ValueStringBuilderThe string builder to append to.
valuestringThe string value to display.
appendLineboolIf true, adds a line break before the value.
hexColorstringHex color code for the value text.
sizestringFont size for the value text.
AppendTo(ref Utf16ValueStringBuilder, string, float, bool, string, string, string, string)
Appends a formatted float value with optional name, color, size, prefix, and suffix directly to an existing string builder. Avoids intermediate string allocations when building composite tooltips.
public static void AppendTo(ref Utf16ValueStringBuilder sb, string valueName, float value, bool appendLine = false, string hexColor = null, string appendPrefix = null, string appendSuffix = null, string size = null)
Parameters
sbUtf16ValueStringBuilderThe string builder to append to.
valueNamestringLabel for the value (e.g., "Health").
valuefloatThe float value to display.
appendLineboolIf true, adds a line break before the value.
hexColorstringHex color code for the value text.
appendPrefixstringOptional prefix to add before the value.
appendSuffixstringOptional suffix to add after the value.
sizestringFont size for the value text.
Format(string, bool, string, string)
Formats a string value with optional color, size, and line break for rich text display. Returns an empty string if value is null or whitespace.
public static string Format(string value, bool appendLine = false, string hexColor = null, string size = null)
Parameters
valuestringThe string value to display.
appendLineboolIf true, adds a line break before the value.
hexColorstringHex color code for the value text.
sizestringFont size for the value text.
Returns
- string
Formatted rich text string.
Format(string, float, bool, string, string, string, string)
Formats a float value with optional name, color, size, prefix, and suffix for rich text display. Returns an empty string if value is zero.
public static string Format(string valueName, float value, bool appendLine = false, string hexColor = null, string appendPrefix = null, string appendSuffix = null, string size = null)
Parameters
valueNamestringLabel for the value (e.g., "Health").
valuefloatThe float value to display.
appendLineboolIf true, adds a line break before the value.
hexColorstringHex color code for the value text.
appendPrefixstringOptional prefix to add before the value.
appendSuffixstringOptional suffix to add after the value.
sizestringFont size for the value text.
Returns
- string
Formatted rich text string.