Files
XCharts/Runtime/Theme/ComponentTheme.cs

102 lines
2.9 KiB
C#
Raw Normal View History

2021-01-11 08:54:28 +08:00
using System;
using UnityEngine;
#if dUI_TextMeshPro
using TMPro;
#endif
2022-02-19 22:37:57 +08:00
namespace XCharts.Runtime
2021-01-11 08:54:28 +08:00
{
[Serializable]
2021-11-23 13:20:07 +08:00
public class ComponentTheme : ChildComponent
2021-01-11 08:54:28 +08:00
{
[SerializeField] protected Font m_Font;
[SerializeField] protected Color m_TextColor;
[SerializeField] protected Color m_TextBackgroundColor;
[SerializeField] protected int m_FontSize = 18;
#if dUI_TextMeshPro
[SerializeField] protected TMP_FontAsset m_TMPFont;
#endif
/// <summary>
/// the font of text.
2023-11-11 23:32:24 +08:00
/// ||字体。
2021-01-11 08:54:28 +08:00
/// </summary>
public Font font
{
get { return m_Font; }
set { m_Font = value; SetComponentDirty(); }
2021-01-11 08:54:28 +08:00
}
/// <summary>
/// the color of text.
2023-11-11 23:32:24 +08:00
/// ||文本颜色。
2021-01-11 08:54:28 +08:00
/// </summary>
public Color textColor
{
get { return m_TextColor; }
set { if (PropertyUtil.SetColor(ref m_TextColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the color of text.
2023-11-11 23:32:24 +08:00
/// ||文本颜色。
2021-01-11 08:54:28 +08:00
/// </summary>
public Color textBackgroundColor
{
get { return m_TextBackgroundColor; }
set { if (PropertyUtil.SetColor(ref m_TextBackgroundColor, value)) SetComponentDirty(); }
}
/// <summary>
/// the font size of text.
2023-11-11 23:32:24 +08:00
/// ||文本字体大小。
2021-01-11 08:54:28 +08:00
/// </summary>
public int fontSize
{
get { return m_FontSize; }
set { if (PropertyUtil.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
}
#if dUI_TextMeshPro
/// <summary>
/// the font of chart text。
2023-11-11 23:32:24 +08:00
/// ||字体。
2021-01-11 08:54:28 +08:00
/// </summary>
public TMP_FontAsset tmpFont
{
get { return m_TMPFont; }
set { m_TMPFont = value; SetComponentDirty(); }
2021-01-11 08:54:28 +08:00
}
#endif
2021-11-23 13:20:07 +08:00
public ComponentTheme(ThemeType theme)
2021-01-11 08:54:28 +08:00
{
2021-11-23 13:20:07 +08:00
m_FontSize = XCSettings.fontSizeLv3;
2021-01-11 08:54:28 +08:00
switch (theme)
{
2021-11-23 13:20:07 +08:00
case ThemeType.Default:
2021-01-11 08:54:28 +08:00
m_TextColor = ColorUtil.GetColor("#514D4D");
break;
2021-11-23 13:20:07 +08:00
case ThemeType.Light:
2021-01-11 08:54:28 +08:00
m_TextColor = ColorUtil.GetColor("#514D4D");
break;
2021-11-23 13:20:07 +08:00
case ThemeType.Dark:
2021-01-11 08:54:28 +08:00
m_TextColor = ColorUtil.GetColor("#B9B8CE");
break;
}
}
public virtual void Copy(ComponentTheme theme)
{
m_Font = theme.font;
m_FontSize = theme.fontSize;
m_TextColor = theme.textColor;
m_TextBackgroundColor = theme.textBackgroundColor;
#if dUI_TextMeshPro
m_TMPFont = theme.tmpFont;
#endif
}
public virtual void Reset(ComponentTheme defaultTheme)
{
Copy(defaultTheme);
}
}
}