Wanted to share this handy extension for those of you who love a good font variation in your debugger. Unity comes with rich text support (rich text format) which makes the output reader so much more handy for complex debugging but it’s a pain if you’re constantly using it with markups. But with this handy extension it’s easy!
Usage:
print("example text in bold".Bold());
print("example text in italics".Italic());
print("example in Color".Color("red"));
print("combine two or more in one".Bold().Color("yellow"));
print("size also but be careful".Size(20));
And here’s the extension, just copy paste to any script and you’ll see it pop up as an option in your editor. I kind of wish Unity would include this as a default. While it seems minor it’s super handy! Enjoy!
Code:
// This is the extension method.
// The first parameter takes the "this" modifier
// and specifies the type for which the method is defined.
public static class StringExtension {
public static string Bold(this string str) => "<b>" + str + "</b>";
public static string Color(this string str,string clr) => string.Format("<color={0}>{1}</color>",clr, str);
public static string Italic(this string str) => "<i>" + str + "</i>";
public static string Size(this string str, int size) => string.Format("<size={0}>{1}</size>",size,str);