2022-07-19 08:22:42 +08:00
|
|
|
using System.Collections.Generic;
|
2021-01-11 08:54:28 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-02-19 22:37:57 +08:00
|
|
|
namespace XCharts.Runtime
|
2021-01-11 08:54:28 +08:00
|
|
|
{
|
|
|
|
|
public static class ColorUtil
|
|
|
|
|
{
|
2022-07-19 08:22:42 +08:00
|
|
|
private static Dictionary<string, Color32> s_ColorCached = new Dictionary<string, Color32>();
|
2021-01-11 08:54:28 +08:00
|
|
|
public static readonly Color32 clearColor32 = new Color32(0, 0, 0, 0);
|
|
|
|
|
public static readonly Vector2 zeroVector2 = Vector2.zero;
|
2022-07-19 08:22:42 +08:00
|
|
|
|
2021-01-11 08:54:28 +08:00
|
|
|
/// <summary>
|
2022-03-24 08:37:06 +08:00
|
|
|
/// Convert the html string to color.
|
2023-11-11 23:32:24 +08:00
|
|
|
/// ||将字符串颜色值转成Color。
|
2021-01-11 08:54:28 +08:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="hexColorStr"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static Color32 GetColor(string hexColorStr)
|
|
|
|
|
{
|
2022-07-19 08:22:42 +08:00
|
|
|
if (s_ColorCached.ContainsKey(hexColorStr))
|
|
|
|
|
{
|
|
|
|
|
return s_ColorCached[hexColorStr];
|
|
|
|
|
}
|
2021-01-11 08:54:28 +08:00
|
|
|
Color color;
|
|
|
|
|
ColorUtility.TryParseHtmlString(hexColorStr, out color);
|
2022-07-19 08:22:42 +08:00
|
|
|
s_ColorCached[hexColorStr] = (Color32) color;
|
|
|
|
|
return s_ColorCached[hexColorStr];
|
2021-01-11 08:54:28 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|