Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Usage:
- m_SideBarTexture = CreateTexture (CreateColor ("#30433C"));
- // The goodness:
- static Color CreateColor (string hexCode, float alpha = 1.0f)
- {
- if (hexCode.Length == 7 && hexCode[0] == '#')
- {
- hexCode = hexCode.Substring (1, 6);
- }
- else if (hexCode.Length != 6)
- {
- throw new System.ArgumentException ("Malformed hex code");
- }
- return new Color (
- ((float)int.Parse (hexCode.Substring (0, 2), NumberStyles.HexNumber)) / 255.0f,
- ((float)int.Parse (hexCode.Substring (2, 2), NumberStyles.HexNumber)) / 255.0f,
- ((float)int.Parse (hexCode.Substring (4, 2), NumberStyles.HexNumber)) / 255.0f,
- alpha
- );
- }
- static Texture2D CreateTexture (Color c)
- {
- Texture2D texture = new Texture2D (2, 2);
- texture.SetPixels (new Color[] {c, c, c, c});
- texture.Apply ();
- return texture;
- }
Add Comment
Please, Sign In to add comment