unity 富文本 拓展string


先上代码
public static class StringTagExt
{
//加粗
public static string AddBoldTag(this string text)
{
return text.AddTag(“b”);
}
//斜体
public static string AddItalicTag(this string text)
{
return text.AddTag(“i”);
}
//字号
public static string AddSizeTag(this string text, int size)
{
return text.AddTag(“size”, size);
}
//颜色
public static string AddColorTag(this string text, string colorName)
{
return text.AddTag(“color”, colorName);
}
//
private static string AddTag(this string text, string tagName)
{
return $"<{tagName}>{text}</{tagName}>";
}
//
private static string AddTag(this string text, string tagName, object value1)
{
return $"<{tagName}="{value1}">{text}</{tagName}>";
}
}

unity 富文本 拓展string