暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ComponentTheme.cs 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using UnityEngine;
  3. #if dUI_TextMeshPro
  4. using TMPro;
  5. #endif
  6. namespace XCharts.Runtime
  7. {
  8. [Serializable]
  9. public class ComponentTheme : ChildComponent
  10. {
  11. [SerializeField] protected Font m_Font;
  12. [SerializeField] protected Color m_TextColor;
  13. [SerializeField] protected Color m_TextBackgroundColor;
  14. [SerializeField] protected int m_FontSize = 18;
  15. #if dUI_TextMeshPro
  16. [SerializeField] protected TMP_FontAsset m_TMPFont;
  17. #endif
  18. /// <summary>
  19. /// the font of text.
  20. /// |字体。
  21. /// </summary>
  22. public Font font
  23. {
  24. get { return m_Font; }
  25. set { m_Font = value; SetComponentDirty(); }
  26. }
  27. /// <summary>
  28. /// the color of text.
  29. /// |文本颜色。
  30. /// </summary>
  31. public Color textColor
  32. {
  33. get { return m_TextColor; }
  34. set { if (PropertyUtil.SetColor(ref m_TextColor, value)) SetComponentDirty(); }
  35. }
  36. /// <summary>
  37. /// the color of text.
  38. /// |文本颜色。
  39. /// </summary>
  40. public Color textBackgroundColor
  41. {
  42. get { return m_TextBackgroundColor; }
  43. set { if (PropertyUtil.SetColor(ref m_TextBackgroundColor, value)) SetComponentDirty(); }
  44. }
  45. /// <summary>
  46. /// the font size of text.
  47. /// |文本字体大小。
  48. /// </summary>
  49. public int fontSize
  50. {
  51. get { return m_FontSize; }
  52. set { if (PropertyUtil.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
  53. }
  54. #if dUI_TextMeshPro
  55. /// <summary>
  56. /// the font of chart text。
  57. /// |字体。
  58. /// </summary>
  59. public TMP_FontAsset tmpFont
  60. {
  61. get { return m_TMPFont; }
  62. set { m_TMPFont = value; SetComponentDirty(); }
  63. }
  64. #endif
  65. public ComponentTheme(ThemeType theme)
  66. {
  67. m_FontSize = XCSettings.fontSizeLv3;
  68. switch (theme)
  69. {
  70. case ThemeType.Default:
  71. m_TextColor = ColorUtil.GetColor("#514D4D");
  72. break;
  73. case ThemeType.Light:
  74. m_TextColor = ColorUtil.GetColor("#514D4D");
  75. break;
  76. case ThemeType.Dark:
  77. m_TextColor = ColorUtil.GetColor("#B9B8CE");
  78. break;
  79. }
  80. }
  81. public virtual void Copy(ComponentTheme theme)
  82. {
  83. m_Font = theme.font;
  84. m_FontSize = theme.fontSize;
  85. m_TextColor = theme.textColor;
  86. m_TextBackgroundColor = theme.textBackgroundColor;
  87. #if dUI_TextMeshPro
  88. m_TMPFont = theme.tmpFont;
  89. #endif
  90. }
  91. public virtual void Reset(ComponentTheme defaultTheme)
  92. {
  93. Copy(defaultTheme);
  94. }
  95. }
  96. }