Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class Util
- {
- public static Color ColorFromHex(string hex)
- {
- hex = hex.Trim();
- if (hex[0] == '#')
- hex = hex.Substring(1, hex.Length-1);
- byte r=0, g=0, b=0;
- if (hex.Length == 6)
- {
- r = byte.Parse(hex.Substring(0,2), System.Globalization.NumberStyles.HexNumber);
- g = byte.Parse(hex.Substring(2,2), System.Globalization.NumberStyles.HexNumber);
- b = byte.Parse(hex.Substring(4,2), System.Globalization.NumberStyles.HexNumber);
- }
- else if (hex.Length == 3)
- {
- r = byte.Parse(hex.Substring(0, 1) + hex.Substring(0, 1), System.Globalization.NumberStyles.HexNumber);
- g = byte.Parse(hex.Substring(1, 1) + hex.Substring(1, 1), System.Globalization.NumberStyles.HexNumber);
- b = byte.Parse(hex.Substring(2, 1) + hex.Substring(2, 1), System.Globalization.NumberStyles.HexNumber);
- }
- return new Color32(r,g,b, 255);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement