LabelLine.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using System;
  2. using UnityEngine;
  3. namespace XCharts.Runtime
  4. {
  5. /// <summary>
  6. /// 标签的引导线
  7. /// </summary>
  8. [System.Serializable]
  9. public class LabelLine : ChildComponent, ISerieComponent, ISerieDataComponent
  10. {
  11. /// <summary>
  12. /// 标签视觉引导线类型
  13. /// </summary>
  14. public enum LineType
  15. {
  16. /// <summary>
  17. /// 折线
  18. /// </summary>
  19. BrokenLine,
  20. /// <summary>
  21. /// 曲线
  22. /// </summary>
  23. Curves,
  24. /// <summary>
  25. /// 水平线
  26. /// </summary>
  27. HorizontalLine
  28. }
  29. [SerializeField] private bool m_Show = true;
  30. [SerializeField] private LineType m_LineType = LineType.BrokenLine;
  31. [SerializeField] private Color32 m_LineColor = ChartConst.clearColor32;
  32. [SerializeField] private float m_LineAngle = 60;
  33. [SerializeField] private float m_LineWidth = 1.0f;
  34. [SerializeField] private float m_LineGap = 1.0f;
  35. [SerializeField] private float m_LineLength1 = 25f;
  36. [SerializeField] private float m_LineLength2 = 15f;
  37. [SerializeField][Since("v3.8.0")] private float m_LineEndX = 0f;
  38. [SerializeField] private SymbolStyle m_StartSymbol = new SymbolStyle() { show = false, type = SymbolType.Circle, size = 3 };
  39. [SerializeField] private SymbolStyle m_EndSymbol = new SymbolStyle() { show = false, type = SymbolType.Circle, size = 3 };
  40. public void Reset()
  41. {
  42. m_Show = false;
  43. m_LineType = LineType.BrokenLine;
  44. m_LineColor = Color.clear;
  45. m_LineAngle = 60;
  46. m_LineWidth = 1.0f;
  47. m_LineGap = 1.0f;
  48. m_LineLength1 = 25f;
  49. m_LineLength2 = 15f;
  50. m_LineEndX = 0;
  51. }
  52. /// <summary>
  53. /// Whether the label line is showed.
  54. /// ||是否显示视觉引导线。
  55. /// </summary>
  56. public bool show
  57. {
  58. get { return m_Show; }
  59. set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
  60. }
  61. /// <summary>
  62. /// the type of visual guide line.
  63. /// ||视觉引导线类型。
  64. /// </summary>
  65. public LineType lineType
  66. {
  67. get { return m_LineType; }
  68. set { if (PropertyUtil.SetStruct(ref m_LineType, value)) SetVerticesDirty(); }
  69. }
  70. /// <summary>
  71. /// the color of visual guild line.
  72. /// ||视觉引导线颜色。默认和serie一致取自调色板。
  73. /// </summary>
  74. public Color32 lineColor
  75. {
  76. get { return m_LineColor; }
  77. set { if (PropertyUtil.SetStruct(ref m_LineColor, value)) SetVerticesDirty(); }
  78. }
  79. /// <summary>
  80. /// the angle of visual guild line. Valid for broken line and curve line. Invalid in Pie.
  81. /// ||视觉引导线的固定角度。对折线和曲线有效。在Pie中无效。
  82. /// </summary>
  83. public float lineAngle
  84. {
  85. get { return m_LineAngle; }
  86. set { if (PropertyUtil.SetStruct(ref m_LineAngle, value)) SetVerticesDirty(); }
  87. }
  88. /// <summary>
  89. /// the width of visual guild line.
  90. /// ||视觉引导线的宽度。
  91. /// </summary>
  92. public float lineWidth
  93. {
  94. get { return m_LineWidth; }
  95. set { if (PropertyUtil.SetStruct(ref m_LineWidth, value)) SetVerticesDirty(); }
  96. }
  97. /// <summary>
  98. /// the gap of container and guild line.
  99. /// ||视觉引导线和容器的间距。
  100. /// </summary>
  101. public float lineGap
  102. {
  103. get { return m_LineGap; }
  104. set { if (PropertyUtil.SetStruct(ref m_LineGap, value)) SetVerticesDirty(); }
  105. }
  106. /// <summary>
  107. /// The length of the first segment of visual guide line.
  108. /// ||视觉引导线第一段的长度。
  109. /// </summary>
  110. public float lineLength1
  111. {
  112. get { return m_LineLength1; }
  113. set { if (PropertyUtil.SetStruct(ref m_LineLength1, value)) SetVerticesDirty(); }
  114. }
  115. /// <summary>
  116. /// The length of the second segment of visual guide line.
  117. /// ||视觉引导线第二段的长度。
  118. /// </summary>
  119. public float lineLength2
  120. {
  121. get { return m_LineLength2; }
  122. set { if (PropertyUtil.SetStruct(ref m_LineLength2, value)) SetVerticesDirty(); }
  123. }
  124. /// <summary>
  125. /// The fixed x position of the end point of visual guide line.
  126. /// ||视觉引导线结束点的固定x位置。当不为0时,会代替lineLength2设定引导线的x位置。
  127. /// </summary>
  128. public float lineEndX
  129. {
  130. get { return m_LineEndX; }
  131. set { if (PropertyUtil.SetStruct(ref m_LineEndX, value)) SetVerticesDirty(); }
  132. }
  133. /// <summary>
  134. /// The symbol of the start point of labelline.
  135. /// ||起始点的图形标记。
  136. /// </summary>
  137. public SymbolStyle startSymbol
  138. {
  139. get { return m_StartSymbol; }
  140. set { if (PropertyUtil.SetClass(ref m_StartSymbol, value)) SetVerticesDirty(); }
  141. }
  142. /// <summary>
  143. /// The symbol of the end point of labelline.
  144. /// ||结束点的图形标记。
  145. /// </summary>
  146. public SymbolStyle endSymbol
  147. {
  148. get { return m_EndSymbol; }
  149. set { if (PropertyUtil.SetClass(ref m_EndSymbol, value)) SetVerticesDirty(); }
  150. }
  151. public Vector3 GetStartSymbolOffset()
  152. {
  153. return m_StartSymbol != null && m_StartSymbol.show ? m_StartSymbol.offset3 : Vector3.zero;
  154. }
  155. public Vector3 GetEndSymbolOffset()
  156. {
  157. return m_EndSymbol != null && m_EndSymbol.show ? m_EndSymbol.offset3 : Vector3.zero;
  158. }
  159. }
  160. }