| 1234567891011121314151617181920212223242526272829303132 |
- using System.Collections;
- using System.Collections.Generic;
- using System.Globalization;
- using UnityEngine;
- namespace WildAttack
- {
- /// <summary>
- /// 颜色转换工具
- /// </summary>
- public class ColorUtils : Singleton<ColorUtils>
- {
- /// <summary>
- /// hex码转换color
- /// </summary>
- /// <param name="hex"></param>
- /// <returns></returns>
- public static Color HexToColor(string hex)
- {
- hex = hex.Replace("0x", string.Empty);
- hex = hex.Replace("#", string.Empty);
- byte a = byte.MaxValue;
- byte r = byte.Parse(hex.Substring(0, 2), NumberStyles.HexNumber);
- byte g = byte.Parse(hex.Substring(2, 2), NumberStyles.HexNumber);
- byte b = byte.Parse(hex.Substring(4, 2), NumberStyles.HexNumber);
- if (hex.Length == 8)
- {
- a = byte.Parse(hex.Substring(6, 2), NumberStyles.HexNumber);
- }
- return new Color32(r, g, b, a);
- }
- }
- }
|