Background.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace XCharts.Runtime
  5. {
  6. /// <summary>
  7. /// Background component.
  8. /// ||背景组件。
  9. /// </summary>
  10. [Serializable]
  11. [DisallowMultipleComponent]
  12. [ComponentHandler(typeof(BackgroundHandler), false, 0)]
  13. public class Background : MainComponent
  14. {
  15. [SerializeField] private bool m_Show = true;
  16. [SerializeField] private Sprite m_Image;
  17. [SerializeField] private Image.Type m_ImageType;
  18. [SerializeField] private Color m_ImageColor = Color.white;
  19. [SerializeField][Since("v3.10.0")] private float m_ImageWidth = 0;
  20. [SerializeField][Since("v3.10.0")] private float m_ImageHeight = 0;
  21. [SerializeField] private bool m_AutoColor = true;
  22. [SerializeField][Since("v3.10.0")] private BorderStyle m_BorderStyle = new BorderStyle();
  23. /// <summary>
  24. /// Whether to enable the background component.
  25. /// ||是否启用背景组件。
  26. /// </summary>
  27. public bool show
  28. {
  29. get { return m_Show; }
  30. set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
  31. }
  32. /// <summary>
  33. /// the image of background.
  34. /// ||背景图。
  35. /// </summary>
  36. public Sprite image
  37. {
  38. get { return m_Image; }
  39. set { if (PropertyUtil.SetClass(ref m_Image, value)) SetComponentDirty(); }
  40. }
  41. /// <summary>
  42. /// the fill type of background image.
  43. /// ||背景图填充类型。
  44. /// </summary>
  45. public Image.Type imageType
  46. {
  47. get { return m_ImageType; }
  48. set { if (PropertyUtil.SetStruct(ref m_ImageType, value)) SetComponentDirty(); }
  49. }
  50. /// <summary>
  51. /// 背景图颜色。
  52. /// </summary>
  53. public Color imageColor
  54. {
  55. get { return m_ImageColor; }
  56. set { if (PropertyUtil.SetColor(ref m_ImageColor, value)) SetComponentDirty(); }
  57. }
  58. /// <summary>
  59. /// the width of background image.
  60. /// ||背景图宽度。
  61. /// </summary>
  62. public float imageWidth
  63. {
  64. get { return m_ImageWidth; }
  65. set { if (PropertyUtil.SetStruct(ref m_ImageWidth, value)) SetComponentDirty(); }
  66. }
  67. /// <summary>
  68. /// the height of background image.
  69. /// ||背景图高度。
  70. /// </summary>
  71. public float imageHeight
  72. {
  73. get { return m_ImageHeight; }
  74. set { if (PropertyUtil.SetStruct(ref m_ImageHeight, value)) SetComponentDirty(); }
  75. }
  76. /// <summary>
  77. /// Whether to use theme background color for component color when the background component is on.
  78. /// ||当background组件开启时,是否自动使用主题背景色作为backgrounnd组件的颜色。当设置为false时,用imageColor作为颜色。
  79. /// </summary>
  80. public bool autoColor
  81. {
  82. get { return m_AutoColor; }
  83. set { if (PropertyUtil.SetStruct(ref m_AutoColor, value)) SetVerticesDirty(); }
  84. }
  85. /// <summary>
  86. /// the border style of background.
  87. /// ||背景边框样式。
  88. /// </summary>
  89. public BorderStyle borderStyle
  90. {
  91. get { return m_BorderStyle; }
  92. set { if (PropertyUtil.SetClass(ref m_BorderStyle, value)) SetComponentDirty(); }
  93. }
  94. public override void SetDefaultValue()
  95. {
  96. m_Show = true;
  97. m_Image = null;
  98. m_ImageType = Image.Type.Sliced;
  99. m_ImageColor = Color.white;
  100. m_AutoColor = true;
  101. }
  102. }
  103. }