Unity控制台console打印富文本

可以用来控制Debug打印文本的 加粗 斜体 大小 颜色

Debug.Log("Hello World".AddBoldTag().AddColorTag("red"));
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}>";
    }
}

 

posted @ 2024-05-21 14:48  weigang  阅读(10)  评论(0编辑  收藏  举报