-
-
Save kirillrybin/5097422 to your computer and use it in GitHub Desktop.
Some Basic Util classes for Unity3D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class ColorUtil | |
{ | |
public static string ColorToHex (Color32 color) | |
{ | |
string hex = color.r.ToString ("X2") + color.g.ToString ("X2") + color.b.ToString ("X2"); | |
return hex; | |
} | |
public static Color HexToColor (string hex) | |
{ | |
byte r = byte.Parse (hex.Substring (0, 2), System.Globalization.NumberStyles.HexNumber); | |
byte g = byte.Parse (hex.Substring (2, 2), System.Globalization.NumberStyles.HexNumber); | |
byte b = byte.Parse (hex.Substring (4, 2), System.Globalization.NumberStyles.HexNumber); | |
return new Color32 (r, g, b, 255); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment