Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Easy Text Format your Debug Logs (Rich Text Format)

Discussion in 'Scripting' started by gabearts, Jun 6, 2020.

  1. gabearts

    gabearts

    Joined:
    Jun 30, 2014
    Posts:
    10
    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!

    Screen Shot 2020-06-06 at 12.17.15 AM.png
    Usage:

    Code (CSharp):
    1.      
    2.         print("example text in bold".Bold());
    3.         print("example text in italics".Italic());
    4.         print("example in Color".Color("red"));
    5.         print("combine two or more in one".Bold().Color("yellow"));
    6.         print("size also but be careful".Size(20));
    7.  
    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:
    Code (CSharp):
    1.      
    2. // This is the extension method.
    3. // The first parameter takes the "this" modifier
    4. // and specifies the type for which the method is defined.
    5. public static class StringExtension {
    6.     public static string Bold(this string str) => "<b>" + str + "</b>";
    7.     public static string Color(this string str,string clr) => string.Format("<color={0}>{1}</color>",clr, str);
    8.     public static string Italic(this string str) => "<i>" + str + "</i>";
    9.     public static string Size(this string str, int size) => string.Format("<size={0}>{1}</size>",size,str);
    10.  
     
    Last edited: Jun 6, 2020
    Nit_Ram, acandael, DaveBars and 21 others like this.
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    THAT is indeed a handy extension... never thought to do this. Clever.
     
    gabearts likes this.
  3. tchris

    tchris

    Joined:
    Oct 10, 2012
    Posts:
    133
    Thanks, very useful
     
  4. alexxUID

    alexxUID

    Joined:
    Jan 14, 2020
    Posts:
    48
    I would like to like this twice!
     
  5. brunogattai1996

    brunogattai1996

    Joined:
    Jan 18, 2020
    Posts:
    5
    Very convenient, thank you!
     
  6. TheGonzoGamer

    TheGonzoGamer

    Joined:
    Apr 24, 2019
    Posts:
    35
    Reporting for Upvote from 2023!