SpriteText.ParseHexColor C# (CSharp) Method

ParseHexColor() protected method

protected ParseHexColor ( string str ) : Color
str string
return Color
	protected Color ParseHexColor(string str)
	{
		if(str.Length < 6)
			return color;

		try
		{
			int red = (System.Int32.Parse(str.Substring(0, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
			int green = (System.Int32.Parse(str.Substring(2, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
			int blue = (System.Int32.Parse(str.Substring(4, 2), System.Globalization.NumberStyles.AllowHexSpecifier));

			int alpha = 255;

			if (str.Length == 8)
				alpha = (System.Int32.Parse(str.Substring(6, 2), System.Globalization.NumberStyles.AllowHexSpecifier));

			return color * new Color(((float)red) / 255f, ((float)green) / 255f, ((float)blue) / 255f, ((float)alpha) / 255f);
		}
		catch
		{
			return color;
		}
	}