8 using System.Collections.Generic;
48 [SerializeField]
private Theme m_Theme =
Theme.Default;
49 [SerializeField]
private string m_ThemeName =
Theme.Default.ToString();
50 [SerializeField]
private string m_FontName;
51 [SerializeField]
private string m_TMPFontName;
52 [SerializeField]
private int m_FontInstacneId;
53 [SerializeField]
private int m_TMPFontInstanceId;
54 [SerializeField]
private Font m_Font;
56 [SerializeField]
private TMP_FontAsset m_TMPFont;
59 [SerializeField]
private Color32 m_ContrastColor;
60 [SerializeField]
private Color32 m_BackgroundColor;
65 [SerializeField]
private List<Color32> m_ColorPalette =
new List<Color32>(13);
71 [SerializeField]
private AxisTheme m_Axis;
85 m_TMPFontName =
"LiberationSans SDF";
94 get {
return m_Theme; }
95 set {
if (PropertyUtil.SetStruct(ref m_Theme, value)) SetComponentDirty(); }
97 public string themeName
99 get {
return m_ThemeName; }
100 set {
if (PropertyUtil.SetClass(ref m_ThemeName, value)) SetComponentDirty(); }
110 get {
return m_ContrastColor; }
111 set {
if (PropertyUtil.SetColor(ref m_ContrastColor, value)) SetVerticesDirty(); }
119 get {
return m_BackgroundColor; }
120 set {
if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
123 public string fontName
125 get {
return m_FontName; }
126 set {
if (PropertyUtil.SetClass(ref m_FontName, value)) SetComponentDirty(); }
128 public int fontInstanceId
130 get {
return m_FontInstacneId; }
131 set {
if (PropertyUtil.SetStruct(ref m_FontInstacneId, value)) SetComponentDirty(); }
133 public string tmpFontName
135 get {
return m_TMPFontName; }
136 set {
if (PropertyUtil.SetClass(ref m_TMPFontName, value)) SetComponentDirty(); }
138 public int tmpFontInstanceId
140 get {
return m_TMPFontInstanceId; }
141 set {
if (PropertyUtil.SetStruct(ref m_TMPFontInstanceId, value)) SetComponentDirty(); }
148 public List<Color32>
colorPalette {
get {
return m_ColorPalette; }
set { m_ColorPalette = value; SetVerticesDirty(); } }
149 public ComponentTheme common {
get {
return m_Common; }
set { m_Common = value; SetComponentDirty(); } }
150 public TitleTheme title {
get {
return m_Title; }
set { m_Title = value; SetComponentDirty(); } }
151 public SubTitleTheme subTitle {
get {
return m_SubTitle; }
set { m_SubTitle = value; SetComponentDirty(); } }
152 public LegendTheme legend {
get {
return m_Legend; }
set { m_Legend = value; SetComponentDirty(); } }
153 public AxisTheme axis {
get {
return m_Axis; }
set { m_Axis = value; SetAllDirty(); } }
154 public RadiusAxisTheme radiusAxis {
get {
return m_RadiusAxis; }
set { m_RadiusAxis = value; SetAllDirty(); } }
155 public AngleAxisTheme angleAxis {
get {
return m_AngleAxis; }
set { m_AngleAxis = value; SetAllDirty(); } }
156 public PolarAxisTheme polar {
get {
return m_Polar; }
set { m_Polar = value; SetAllDirty(); } }
157 public GaugeAxisTheme gauge {
get {
return m_Gauge; }
set { m_Gauge = value; SetAllDirty(); } }
158 public RadarAxisTheme radar {
get {
return m_Radar; }
set { m_Radar = value; SetAllDirty(); } }
159 public TooltipTheme tooltip {
get {
return m_Tooltip; }
set { m_Tooltip = value; SetAllDirty(); } }
160 public DataZoomTheme dataZoom {
get {
return m_DataZoom; }
set { m_DataZoom = value; SetAllDirty(); } }
161 public VisualMapTheme visualMap {
get {
return m_VisualMap; }
set { m_VisualMap = value; SetAllDirty(); } }
162 public SerieTheme serie {
get {
return m_Serie; }
set { m_Serie = value; SetVerticesDirty(); } }
164 public TMP_FontAsset tmpFont
170 get {
return m_TMPFont; }
176 m_TMPFontName = value.name;
177 m_TMPFontInstanceId = value.GetInstanceID();
180 SyncTMPFontToSubComponent();
190 get {
return m_Font; }
196 m_FontName = value.name;
197 m_FontInstacneId = value.GetInstanceID();
200 SyncFontToSubComponent();
204 public void SetDefaultFont()
208 SyncTMPFontToSubComponent();
211 SyncFontToSubComponent();
223 if (index < 0) index = 0;
224 var newIndex = index < m_ColorPalette.Count ? index : index % m_ColorPalette.Count;
225 if (newIndex < m_ColorPalette.Count)
226 return m_ColorPalette[newIndex];
227 else return Color.clear;
230 public void SetColorPalette(List<Color32> colorList)
232 m_ColorPalette = colorList;
235 public void SetColorPalette(List<string> hexColorStringList)
237 m_ColorPalette.Clear();
238 foreach (var hexColor
in hexColorStringList)
239 m_ColorPalette.Add(ColorUtil.GetColor(hexColor));
243 public void CheckWarning(StringBuilder sb)
246 if (m_TMPFont ==
null)
248 sb.AppendFormat(
"warning:theme->tmpFont is null\n");
253 sb.AppendFormat(
"warning:theme->font is null\n");
256 if (m_ColorPalette.Count == 0)
258 sb.AppendFormat(
"warning:theme->colorPalette is empty\n");
260 for (
int i = 0; i < m_ColorPalette.Count; i++)
262 if (!ChartHelper.IsClearColor(m_ColorPalette[i]) && m_ColorPalette[i].a == 0)
263 sb.AppendFormat(
"warning:theme->colorPalette[{0}] alpha = 0\n", i);
267 Dictionary<int, string> _colorDic =
new Dictionary<int, string>();
280 index = index % m_ColorPalette.Count;
281 if (_colorDic.ContainsKey(index))
return _colorDic[index];
284 _colorDic[index] = ColorUtility.ToHtmlStringRGBA(
GetColor(index));
285 return _colorDic[index];
312 m_Theme =
theme.theme;
313 m_ThemeName =
theme.themeName;
315 tmpFont =
theme.tmpFont;
318 m_FontName =
theme.fontName;
319 m_FontInstacneId =
theme.fontInstanceId;
320 m_TMPFontName =
theme.tmpFontName;
321 m_TMPFontInstanceId =
theme.tmpFontInstanceId;
322 m_ContrastColor =
theme.contrastColor;
323 m_BackgroundColor =
theme.m_BackgroundColor;
324 m_Common.Copy(
theme.common);
325 m_Legend.Copy(
theme.m_Legend);
326 m_Title.Copy(
theme.m_Title);
327 m_SubTitle.Copy(
theme.m_SubTitle);
328 m_Axis.Copy(
theme.axis);
329 m_RadiusAxis.Copy(
theme.radiusAxis);
330 m_AngleAxis.Copy(
theme.angleAxis);
331 m_Polar.Copy(
theme.polar);
332 m_Gauge.Copy(
theme.gauge);
333 m_Radar.Copy(
theme.radar);
334 m_Tooltip.Copy(
theme.tooltip);
335 m_DataZoom.Copy(
theme.dataZoom);
336 m_VisualMap.Copy(
theme.visualMap);
337 m_Serie.Copy(
theme.serie);
338 ChartHelper.CopyList(m_ColorPalette,
theme.colorPalette);
354 var sourTheme = XThemeMgr.GetTheme(themeName);
355 if (sourTheme !=
null)
357 CopyTheme(sourTheme);
361 Debug.LogWarning(
"ResetTheme:can't find theme:" + themeName +
", reset to Default theme");
375 InitChartComponentTheme(
theme);
376 theme.CopyTheme(
this);
393 theme.contrastColor = ColorUtil.GetColor(
"#514D4D");
394 theme.backgroundColor =
new Color32(255, 255, 255, 255);
395 theme.colorPalette =
new List<Color32>
397 new Color32(194, 53, 49, 255),
398 new Color32(47, 69, 84, 255),
399 new Color32(97, 160, 168, 255),
400 new Color32(212, 130, 101, 255),
401 new Color32(145, 199, 174, 255),
402 new Color32(116, 159, 131, 255),
403 new Color32(202, 134, 34, 255),
404 new Color32(189, 162, 154, 255),
405 new Color32(110, 112, 116, 255),
406 new Color32(84, 101, 112, 255),
407 new Color32(196, 204, 211, 255)
409 InitChartComponentTheme(
theme);
426 theme.contrastColor = ColorUtil.GetColor(
"#514D4D");
427 theme.backgroundColor =
new Color32(255, 255, 255, 255);
428 theme.colorPalette =
new List<Color32>
430 ColorUtil.GetColor(
"#37A2DA"),
431 ColorUtil.GetColor(
"#32C5E9"),
432 ColorUtil.GetColor(
"#67E0E3"),
433 ColorUtil.GetColor(
"#9FE6B8"),
434 ColorUtil.GetColor(
"#FFDB5C"),
435 ColorUtil.GetColor(
"#ff9f7f"),
436 ColorUtil.GetColor(
"#fb7293"),
437 ColorUtil.GetColor(
"#E062AE"),
438 ColorUtil.GetColor(
"#E690D1"),
439 ColorUtil.GetColor(
"#e7bcf3"),
440 ColorUtil.GetColor(
"#9d96f5"),
441 ColorUtil.GetColor(
"#8378EA"),
442 ColorUtil.GetColor(
"#96BFFF"),
444 InitChartComponentTheme(
theme);
461 theme.contrastColor = ColorUtil.GetColor(
"#B9B8CE");
462 theme.backgroundColor = ColorUtil.GetColor(
"#100C2A");
463 theme.colorPalette =
new List<Color32>
465 ColorUtil.GetColor(
"#4992ff"),
466 ColorUtil.GetColor(
"#7cffb2"),
467 ColorUtil.GetColor(
"#fddd60"),
468 ColorUtil.GetColor(
"#ff6e76"),
469 ColorUtil.GetColor(
"#58d9f9"),
470 ColorUtil.GetColor(
"#05c091"),
471 ColorUtil.GetColor(
"#ff8a45"),
472 ColorUtil.GetColor(
"#8d48e3"),
473 ColorUtil.GetColor(
"#dd79ff"),
475 InitChartComponentTheme(
theme);
487 theme.contrastColor = Color.clear;
488 theme.backgroundColor = Color.clear;
489 theme.colorPalette =
new List<Color32>();
490 InitChartComponentTheme(
theme);
495 public void SyncFontName()
499 m_FontName =
font.name;
500 m_FontInstacneId =
font.GetInstanceID();
505 m_TMPFontName = tmpFont.name;
506 m_TMPFontInstanceId = tmpFont.GetInstanceID();
511 public void SyncFontToSubComponent()
529 public void SyncTMPFontToSubComponent()
531 common.tmpFont = tmpFont;
532 title.tmpFont = tmpFont;
533 subTitle.tmpFont = tmpFont;
534 legend.tmpFont = tmpFont;
535 axis.tmpFont = tmpFont;
536 radiusAxis.tmpFont = tmpFont;
537 angleAxis.tmpFont = tmpFont;
538 polar.tmpFont = tmpFont;
539 gauge.tmpFont = tmpFont;
540 radar.tmpFont = tmpFont;
541 tooltip.tmpFont = tmpFont;
542 dataZoom.tmpFont = tmpFont;
543 visualMap.tmpFont = tmpFont;
547 private static void InitChartComponentTheme(ChartTheme
theme)
549 theme.common =
new ComponentTheme(
theme.theme);
551 theme.subTitle =
new SubTitleTheme(
theme.theme);
554 theme.radiusAxis =
new RadiusAxisTheme(
theme.theme);
555 theme.angleAxis =
new AngleAxisTheme(
theme.theme);
556 theme.polar =
new PolarAxisTheme(
theme.theme);
557 theme.gauge =
new GaugeAxisTheme(
theme.theme);
558 theme.radar =
new RadarAxisTheme(
theme.theme);
559 theme.tooltip =
new TooltipTheme(
theme.theme);
560 theme.dataZoom =
new DataZoomTheme(
theme.theme);
561 theme.visualMap =
new VisualMapTheme(
theme.theme);
563 theme.SetDefaultFont();
575 ColorUtility.TryParseHtmlString(hexColorStr, out color);
576 return (Color32)color;
579 public override int GetHashCode()
581 return base.GetHashCode();