Guest User

Untitled

a guest
Nov 19th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. // Usage:
  2.  
  3. m_SideBarTexture = CreateTexture (CreateColor ("#30433C"));
  4.  
  5. // The goodness:
  6.  
  7. static Color CreateColor (string hexCode, float alpha = 1.0f)
  8. {
  9. if (hexCode.Length == 7 && hexCode[0] == '#')
  10. {
  11. hexCode = hexCode.Substring (1, 6);
  12. }
  13. else if (hexCode.Length != 6)
  14. {
  15. throw new System.ArgumentException ("Malformed hex code");
  16. }
  17.  
  18. return new Color (
  19. ((float)int.Parse (hexCode.Substring (0, 2), NumberStyles.HexNumber)) / 255.0f,
  20. ((float)int.Parse (hexCode.Substring (2, 2), NumberStyles.HexNumber)) / 255.0f,
  21. ((float)int.Parse (hexCode.Substring (4, 2), NumberStyles.HexNumber)) / 255.0f,
  22. alpha
  23. );
  24. }
  25.  
  26.  
  27. static Texture2D CreateTexture (Color c)
  28. {
  29. Texture2D texture = new Texture2D (2, 2);
  30. texture.SetPixels (new Color[] {c, c, c, c});
  31. texture.Apply ();
  32.  
  33. return texture;
  34. }
Add Comment
Please, Sign In to add comment