Skip to content

Instantly share code, notes, and snippets.

@hariedo
Created December 23, 2025 00:42
Show Gist options
  • Select an option

  • Save hariedo/74dd85063efb54c01a4ac97df3a39916 to your computer and use it in GitHub Desktop.

Select an option

Save hariedo/74dd85063efb54c01a4ac97df3a39916 to your computer and use it in GitHub Desktop.
// UnityColorUtilities.cs
//
using UnityEngine;
public static class ColorUtilities
{
public static Color HexRGB(uint hexcode)
{
// e.g., 0xFF0033
float b = (hexcode & 0xFF) / 255f;
float g = ((hexcode >> 8) & 0xFF) / 255f;
float r = ((hexcode >> 16) & 0xFF) / 255f;
return new Color(r, g, b);
}
public static Color HexRGBA(uint hexcode)
{
// e.g., 0xFF003380
float a = (hexcode & 0xFF) / 255f;
float b = ((hexcode >> 8) & 0xFF) / 255f;
float g = ((hexcode >> 16) & 0xFF) / 255f;
float r = ((hexcode >> 24) & 0xFF) / 255f;
return new Color(r, g, b, a);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment