You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.8 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UltraCombos.Frozen.RoyalGallery
{
public class Utils
{
public static Color32 HexToColor(string hex)
{
hex = hex.Replace("0x", "");//in case the string is formatted 0xFFFFFF
hex = hex.Replace("#", "");//in case the string is formatted #FFFFFF
byte a = 255;//assume fully visible unless specified in 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);
//Only use alpha if the string has enough characters
if (hex.Length == 8)
{
a = byte.Parse(hex.Substring(6, 2), System.Globalization.NumberStyles.HexNumber);
}
return new Color32(r, g, b, a);
}
public static string ColorToHex(Color32 color)
{
string hex = color.r.ToString("X2") + color.g.ToString("X2") + color.b.ToString("X2");
return hex;
}
public static string GenerateSerial(int dev_id, string page_id)
{
string dev_sid = dev_id.ToString("X");
string date = System.DateTime.Now.ToString("HHmmss");
string res_sid = page_id;
try
{
res_sid = System.Int32.Parse(res_sid).ToString("X");
}
catch (System.FormatException)
{
Debug.LogWarning($"GenerateSerial: rid={res_sid} is not number.");
}
return $"{date}{dev_sid}{res_sid}";
}
}
}