Skip to content

Instantly share code, notes, and snippets.

@paulhayes
Last active July 20, 2022 11:37
Show Gist options
  • Save paulhayes/9e4f2251887a10f56394 to your computer and use it in GitHub Desktop.
Save paulhayes/9e4f2251887a10f56394 to your computer and use it in GitHub Desktop.
Extension to Unity3d Color and Color32. Allows easy converting of Color to hex string.
using UnityEngine;
using System.Collections;
public static class ColorExt {
public static string ToHexString(this Color32 c){
return string.Format ("{0:X2}{1:X2}{2:X2}", c.r, c.g, c.b);
}
public static string ToHexString(this Color color){
Color32 c = color;
return c.ToHexString();
}
public static int ToHex(this Color32 c){
return (c.r<<16)|(c.g<<8)|(c.b);
}
public static int ToHex(this Color color){
Color32 c = color;
return c.ToHex();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment