Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DockyColor {
- static float convert = 0.00390625f;
- public static Color RGBA(int r, int g, int b, int a)
- {
- return new Color(r * convert, g * convert, b * convert, a * convert);
- }
- public static Color RGB(int r, int g, int b)
- {
- return new Color(r * convert, g * convert, b * convert);
- }
- public static Color Hex(string hex)
- {
- if (hex.Length == 6) {
- return HexRGBToColor(hex);
- }
- if (hex.Length == 8) {
- return HexRGBAToColor(hex);
- }
- Debug.LogError("Invalid Color!");
- return invisible;
- }
- public static Color HexRGBToColor(string colorString)
- {
- float div = 1f / 256;
- float r = System.Convert.ToInt32(colorString.Substring(0, 2), 16) * div;
- float g = System.Convert.ToInt32(colorString.Substring(2, 2), 16) * div;
- float b = System.Convert.ToInt32(colorString.Substring(4, 2), 16) * div;
- return new Color(r, g, b, 1);
- }
- public static Color HexRGBAToColor(string colorString)
- {
- float div = 1f / 256;
- float r = System.Convert.ToInt32(colorString.Substring(0, 2), 16) * div;
- float g = System.Convert.ToInt32(colorString.Substring(2, 2), 16) * div;
- float b = System.Convert.ToInt32(colorString.Substring(4, 2), 16) * div;
- float a = System.Convert.ToInt32(colorString.Substring(6, 2), 16) * div;
- return new Color(r, g, b, a);
- }
- public static Color nicePink { get { return RGB(255,240,245); }}
- public static Color tomato { get { return RGB(255,99,71); }}
- public static Color poop { get { return RGB(160,82,45); }}
- public static Color invisible { get { return RGBA(0,0,0,0); }}
- }
Advertisement
Add Comment
Please, Sign In to add comment