暫無描述
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.

AxisSplitLine.cs 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using UnityEngine;
  3. namespace XCharts.Runtime
  4. {
  5. /// <summary>
  6. /// Split line of axis in grid area.
  7. /// |坐标轴在 grid 区域中的分隔线。
  8. /// </summary>
  9. [Serializable]
  10. public class AxisSplitLine : BaseLine
  11. {
  12. [SerializeField] private int m_Interval;
  13. [SerializeField] private float m_Distance;
  14. [SerializeField] private bool m_AutoColor;
  15. [SerializeField][Since("v3.3.0")] private bool m_ShowStartLine = true;
  16. [SerializeField][Since("v3.3.0")] private bool m_ShowEndLine = true;
  17. /// <summary>
  18. /// The distance between the split line and axis line.
  19. /// |刻度线与轴线的距离。
  20. /// </summary>
  21. public float distance { get { return m_Distance; } set { m_Distance = value; } }
  22. /// <summary>
  23. /// auto color.
  24. /// |自动设置颜色。
  25. /// </summary>
  26. public bool autoColor { get { return m_AutoColor; } set { m_AutoColor = value; } }
  27. /// <summary>
  28. /// Interval of Axis splitLine.
  29. /// |坐标轴分隔线的显示间隔。
  30. /// </summary>
  31. public int interval
  32. {
  33. get { return m_Interval; }
  34. set { if (PropertyUtil.SetStruct(ref m_Interval, value)) SetVerticesDirty(); }
  35. }
  36. /// <summary>
  37. /// Whether to show the first split line.
  38. /// |是否显示第一条分割线。
  39. /// </summary>
  40. public bool showStartLine
  41. {
  42. get { return m_ShowStartLine; }
  43. set { if (PropertyUtil.SetStruct(ref m_ShowStartLine, value)) SetVerticesDirty(); }
  44. }
  45. /// <summary>
  46. /// Whether to show the last split line.
  47. /// |是否显示最后一条分割线。
  48. /// </summary>
  49. public bool showEndLine
  50. {
  51. get { return m_ShowEndLine; }
  52. set { if (PropertyUtil.SetStruct(ref m_ShowEndLine, value)) SetVerticesDirty(); }
  53. }
  54. public override bool vertsDirty { get { return m_VertsDirty || m_LineStyle.anyDirty; } }
  55. public override void ClearVerticesDirty()
  56. {
  57. base.ClearVerticesDirty();
  58. m_LineStyle.ClearVerticesDirty();
  59. }
  60. public static AxisSplitLine defaultSplitLine
  61. {
  62. get
  63. {
  64. return new AxisSplitLine()
  65. {
  66. m_Show = false,
  67. };
  68. }
  69. }
  70. public AxisSplitLine Clone()
  71. {
  72. var axisSplitLine = new AxisSplitLine();
  73. axisSplitLine.show = show;
  74. axisSplitLine.interval = interval;
  75. axisSplitLine.showStartLine = showStartLine;
  76. axisSplitLine.showEndLine = showEndLine;
  77. axisSplitLine.lineStyle = lineStyle.Clone();
  78. return axisSplitLine;
  79. }
  80. public void Copy(AxisSplitLine splitLine)
  81. {
  82. base.Copy(splitLine);
  83. interval = splitLine.interval;
  84. showStartLine = splitLine.showStartLine;
  85. showEndLine = splitLine.showEndLine;
  86. }
  87. internal bool NeedShow(int index, int total)
  88. {
  89. if (!show) return false;
  90. if (interval != 0 && index % (interval + 1) != 0) return false;
  91. if (!showStartLine && index == 0) return false;
  92. if (!showEndLine && index == total - 1) return false;
  93. return true;
  94. }
  95. }
  96. }