Created
March 2, 2018 05:54
-
-
Save nir1082/bf49006af4554f5956d4dd12bd541218 to your computer and use it in GitHub Desktop.
[Unity] リッチテキストを簡単に扱うためのクラス (license: WTFPL)
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
namespace NIR1082 | |
{ | |
public class RichText | |
{ | |
#region Statics | |
static public string Bold (string str) | |
{ | |
return "<b>" + str + "</b>"; | |
} | |
static public string Italic (string str) | |
{ | |
return "<i>" + str + "</i>"; | |
} | |
static public string Size (string str, int size) | |
{ | |
return "<size=" + size + ">" + str + "</size>"; | |
} | |
static public string Color (string str, UnityEngine.Color color) | |
{ | |
return string.Format ("<color=#{0:G}>{1:G}</color>", UnityEngine.ColorUtility.ToHtmlStringRGB (color), str); | |
} | |
static public string Color (string str, string colorCode) | |
{ | |
return "<color=" + colorCode + ">" + str + "</color>"; | |
} | |
#endregion | |
#region Constructors | |
public RichText () | |
{ | |
new RichText ("", false, false, 0, UnityEngine.Color.black); | |
} | |
public RichText (string str, bool bold, bool italic, int size, UnityEngine.Color color) | |
{ | |
origin = str; | |
isBold = bold; | |
isItalic = italic; | |
this.size = size; | |
this.color = color; | |
} | |
#endregion | |
#region Properties | |
public string origin { | |
get; | |
set; | |
} | |
public bool isBold { | |
get; | |
set; | |
} | |
public bool isItalic { | |
get; | |
set; | |
} | |
public int size { | |
get; | |
set; | |
} | |
public UnityEngine.Color color { | |
get; | |
set; | |
} | |
#endregion | |
#region Methods | |
public override string ToString () | |
{ | |
string str = origin; | |
if (isBold) { | |
str = RichText.Bold (str); | |
} | |
if (isItalic) { | |
str = RichText.Italic (str); | |
} | |
str = RichText.Size (str, size); | |
str = RichText.Color (str, UnityEngine.ColorUtility.ToHtmlStringRGB (color)); | |
return str; | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment