BorderStyle.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace XCharts.Runtime
  4. {
  5. /// <summary>
  6. /// The style of border.
  7. /// ||边框样式。
  8. /// </summary>
  9. [System.Serializable]
  10. [Since("v3.10.0")]
  11. public class BorderStyle : ChildComponent
  12. {
  13. [SerializeField] private bool m_Show = false;
  14. [SerializeField] private float m_BorderWidth;
  15. [SerializeField] private Color32 m_BorderColor;
  16. [SerializeField] private bool m_RoundedCorner = true;
  17. [SerializeField] private float[] m_CornerRadius = new float[] { 0, 0, 0, 0 };
  18. /// <summary>
  19. /// whether the border is visible.
  20. /// ||是否显示边框。
  21. /// </summary>
  22. public bool show
  23. {
  24. get { return m_Show; }
  25. set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
  26. }
  27. /// <summary>
  28. /// the width of border.
  29. /// ||边框宽度。
  30. /// </summary>
  31. public float borderWidth
  32. {
  33. get { return m_BorderWidth; }
  34. set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetAllDirty(); }
  35. }
  36. /// <summary>
  37. /// the color of border.
  38. /// ||边框颜色。
  39. /// </summary>
  40. public Color32 borderColor
  41. {
  42. get { return m_BorderColor; }
  43. set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetAllDirty(); }
  44. }
  45. /// <summary>
  46. /// whether the border is rounded corner.
  47. /// ||是否显示圆角。
  48. /// </summary>
  49. public bool roundedCorner
  50. {
  51. get { return m_RoundedCorner; }
  52. set { if (PropertyUtil.SetStruct(ref m_RoundedCorner, value)) SetAllDirty(); }
  53. }
  54. /// <summary>
  55. /// The radius of rounded corner. Its unit is px. Use array to respectively specify the 4 corner radiuses((clockwise upper left,
  56. /// upper right, bottom right and bottom left)). When is set to (1,1,1,1), all corners are rounded.
  57. /// ||圆角半径。用数组分别指定4个圆角半径(顺时针左上,右上,右下,左下)。当为(1,1,1,1)时为全圆角。
  58. /// </summary>
  59. public float[] cornerRadius
  60. {
  61. get { return m_CornerRadius; }
  62. set { if (PropertyUtil.SetClass(ref m_CornerRadius, value)) SetAllDirty(); }
  63. }
  64. public float GetRuntimeBorderWidth()
  65. {
  66. return m_Show ? m_BorderWidth : 0;
  67. }
  68. public Color32 GetRuntimeBorderColor()
  69. {
  70. return m_Show ? m_BorderColor : ColorUtil.clearColor32;
  71. }
  72. public float[] GetRuntimeCornerRadius()
  73. {
  74. return m_Show && roundedCorner ? m_CornerRadius : null;
  75. }
  76. }
  77. }