duck

duck

Oct 15th, 2010
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. class DockyColor {
  2.  
  3.     static float convert = 0.00390625f;
  4.  
  5.     public static Color RGBA(int r, int g, int b, int a)
  6.     {
  7.         return new Color(r * convert, g * convert, b * convert, a * convert);    
  8.     }
  9.  
  10.     public static Color RGB(int r, int g, int b)
  11.     {
  12.         return new Color(r * convert, g * convert, b * convert);    
  13.     }
  14.    
  15.     public static Color Hex(string hex)
  16.     {
  17.         if (hex.Length == 6) {
  18.             return HexRGBToColor(hex);
  19.         }
  20.        
  21.         if (hex.Length == 8) {
  22.             return HexRGBAToColor(hex);
  23.         }
  24.        
  25.         Debug.LogError("Invalid Color!");
  26.         return invisible;
  27.        
  28.     }
  29.  
  30.     public static Color HexRGBToColor(string colorString)
  31.     {
  32.         float div = 1f / 256;
  33.         float r = System.Convert.ToInt32(colorString.Substring(0, 2), 16) * div;
  34.         float g = System.Convert.ToInt32(colorString.Substring(2, 2), 16) * div;
  35.         float b = System.Convert.ToInt32(colorString.Substring(4, 2), 16) * div;
  36.         return new Color(r, g, b, 1);
  37.     }
  38.  
  39.     public static Color HexRGBAToColor(string colorString)
  40.     {
  41.         float div = 1f / 256;
  42.         float r = System.Convert.ToInt32(colorString.Substring(0, 2), 16) * div;
  43.         float g = System.Convert.ToInt32(colorString.Substring(2, 2), 16) * div;
  44.         float b = System.Convert.ToInt32(colorString.Substring(4, 2), 16) * div;
  45.         float a = System.Convert.ToInt32(colorString.Substring(6, 2), 16) * div;
  46.         return new Color(r, g, b, a);
  47.     }
  48.    
  49.     public static Color nicePink { get { return  RGB(255,240,245); }}
  50.     public static Color tomato { get { return RGB(255,99,71); }}
  51.     public static Color poop { get { return RGB(160,82,45); }}
  52.     public static Color invisible { get { return RGBA(0,0,0,0); }}
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment