Skip to content

Instantly share code, notes, and snippets.

@kirillrybin
Last active December 14, 2015 13:59
Show Gist options
  • Save kirillrybin/5097422 to your computer and use it in GitHub Desktop.
Save kirillrybin/5097422 to your computer and use it in GitHub Desktop.
Some Basic Util classes for Unity3D
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