Created
March 4, 2018 11:16
-
-
Save atori708/ecf61e674141695a910958e183f41d3d to your computer and use it in GitHub Desktop.
String extension methods for Unity Richtext. Color, Size, Bold and Italic.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
/// <summary> | |
/// Extension methods for string. | |
/// </summary> | |
public static class StringExtension{ | |
public static string Bold(this string str) | |
{ | |
return "<b>" + str + "</b>"; | |
} | |
public static string Italic(this string str) | |
{ | |
return "<i>" + str + "</i>"; | |
} | |
public static string Size(this string str, int size) | |
{ | |
return string.Format("<size=\"{0}\">", size) + str + "</size>"; | |
} | |
public static string Aqua(this string str) | |
{ | |
return AddColorTag (str, "aqua"); | |
} | |
public static string Blue(this string str) | |
{ | |
return AddColorTag (str, "blue"); | |
} | |
public static string Black(this string str) | |
{ | |
return AddColorTag (str, "black"); | |
} | |
public static string Brown(this string str) | |
{ | |
return AddColorTag (str, "brown"); | |
} | |
public static string Cyan(this string str) | |
{ | |
return AddColorTag (str, "cyan"); | |
} | |
public static string DarkBlue(this string str) | |
{ | |
return AddColorTag (str, "darkblue"); | |
} | |
public static string Fuchsia(this string str) | |
{ | |
return AddColorTag (str, "fuchsia"); | |
} | |
public static string Green(this string str) | |
{ | |
return AddColorTag (str, "green"); | |
} | |
public static string Grey(this string str) | |
{ | |
return AddColorTag (str, "grey"); | |
} | |
public static string LightBlue(this string str) | |
{ | |
return AddColorTag (str, "lightblue"); | |
} | |
public static string Lime(this string str) | |
{ | |
return AddColorTag (str, "lime"); | |
} | |
public static string Magenta(this string str) | |
{ | |
return AddColorTag (str, "magenta"); | |
} | |
public static string Maroon(this string str) | |
{ | |
return AddColorTag (str, "maroon"); | |
} | |
public static string Navy(this string str) | |
{ | |
return AddColorTag (str, "navy"); | |
} | |
public static string Olive(this string str) | |
{ | |
return AddColorTag (str, "olive"); | |
} | |
public static string Orange(this string str) | |
{ | |
return AddColorTag (str, "orange"); | |
} | |
public static string Purple(this string str) | |
{ | |
return AddColorTag (str, "purple"); | |
} | |
public static string Red(this string str) | |
{ | |
return AddColorTag (str, "red"); | |
} | |
public static string Silver(this string str) | |
{ | |
return AddColorTag (str, "silver"); | |
} | |
public static string Teal(this string str) | |
{ | |
return AddColorTag (str, "teal"); | |
} | |
public static string White(this string str) | |
{ | |
return AddColorTag (str, "white"); | |
} | |
public static string Yellow(this string str) | |
{ | |
return AddColorTag (str, "yellow"); | |
} | |
public static string Color(this string str, string color) | |
{ | |
return AddColorTag (str, color); | |
} | |
static string AddColorTag(string str, string color) { | |
return string.Format("<color=\"{0}\">", color) + str + "</color>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment