mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-18 06:20:15 +00:00
整理代码结构,支持Package Manager添加
This commit is contained in:
67
Scripts/Runtime/Utility/ChartCached.cs
Normal file
67
Scripts/Runtime/Utility/ChartCached.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public static class ChartCached
|
||||
{
|
||||
private static Dictionary<float, string> s_ValueToF1Str = new Dictionary<float, string>(1000);
|
||||
private static Dictionary<float, string> s_ValueToF2Str = new Dictionary<float, string>(1000);
|
||||
private static Dictionary<float, string> s_ValueToStr = new Dictionary<float, string>(1000);
|
||||
private static Dictionary<int, string> s_IntToStr = new Dictionary<int, string>(1000);
|
||||
private static Dictionary<Color, string> s_ColorToStr = new Dictionary<Color, string>(1000);
|
||||
|
||||
public static string FloatToStr(float value, int f = 0)
|
||||
{
|
||||
if (f > 2) f = 2;
|
||||
Dictionary<float, string> valueDic;
|
||||
if (f == 1) valueDic = s_ValueToF1Str;
|
||||
else if (f == 2) valueDic = s_ValueToF2Str;
|
||||
else valueDic = s_ValueToStr;
|
||||
if (valueDic.ContainsKey(value))
|
||||
{
|
||||
return valueDic[value];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (f == 1) valueDic[value] = value.ToString("f1");
|
||||
else if (f == 2) valueDic[value] = value.ToString("f2");
|
||||
else valueDic[value] = value.ToString();
|
||||
return valueDic[value];
|
||||
}
|
||||
}
|
||||
|
||||
public static string IntToStr(int value)
|
||||
{
|
||||
if (s_IntToStr.ContainsKey(value))
|
||||
{
|
||||
return s_IntToStr[value];
|
||||
}
|
||||
else
|
||||
{
|
||||
s_IntToStr[value] = value.ToString();
|
||||
return s_IntToStr[value];
|
||||
}
|
||||
}
|
||||
|
||||
public static string ColorToStr(Color color)
|
||||
{
|
||||
if (s_ColorToStr.ContainsKey(color))
|
||||
{
|
||||
return s_ColorToStr[color];
|
||||
}
|
||||
else
|
||||
{
|
||||
s_ColorToStr[color] = ColorUtility.ToHtmlStringRGBA(color);
|
||||
return s_ColorToStr[color];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user