26 lines
896 B
C#
26 lines
896 B
C#
namespace Guru
|
|
{
|
|
using UnityEngine;
|
|
|
|
|
|
public static class GuruSDKUtils
|
|
{
|
|
public static Color HexToColor(string hexString)
|
|
{
|
|
if(string.IsNullOrEmpty(hexString)) return Color.clear;
|
|
|
|
var hex = hexString.Replace("#", "");
|
|
if(hex.Length < 6) return Color.clear;
|
|
|
|
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);
|
|
byte a = 255;
|
|
if (hex.Length >= 8)
|
|
{
|
|
a = byte.Parse(hex.Substring(6, 2), System.Globalization.NumberStyles.HexNumber);
|
|
}
|
|
return new Color(r, g, b, a);
|
|
}
|
|
}
|
|
} |