Settings.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. using System;
  2. using UnityEngine;
  3. namespace XCharts.Runtime
  4. {
  5. /// <summary>
  6. /// Global parameter setting component. The default value can be used in general, and can be adjusted when necessary.
  7. /// ||全局参数设置组件。一般情况下可使用默认值,当有需要时可进行调整。
  8. /// </summary>
  9. [Serializable]
  10. public class Settings : MainComponent
  11. {
  12. [SerializeField] private bool m_Show = true;
  13. [SerializeField][Range(1, 20)] protected int m_MaxPainter = 10;
  14. [SerializeField] protected bool m_ReversePainter = false;
  15. [SerializeField] protected Material m_BasePainterMaterial;
  16. [SerializeField] protected Material m_SeriePainterMaterial;
  17. [SerializeField] protected Material m_UpperPainterMaterial;
  18. [SerializeField] protected Material m_TopPainterMaterial;
  19. [SerializeField][Range(1, 10)] protected float m_LineSmoothStyle = 2.5f;
  20. [SerializeField][Range(1f, 20)] protected float m_LineSmoothness = 2f;
  21. [SerializeField][Range(0.5f, 20)] protected float m_LineSegmentDistance = 3f;
  22. [SerializeField][Range(1, 10)] protected float m_CicleSmoothness = 2f;
  23. [SerializeField] protected float m_LegendIconLineWidth = 2;
  24. [SerializeField] private float[] m_LegendIconCornerRadius = new float[] { 0.25f, 0.25f, 0.25f, 0.25f };
  25. [SerializeField][Since("v3.1.0")] protected float m_AxisMaxSplitNumber = 50;
  26. public bool show { get { return m_Show; } }
  27. /// <summary>
  28. /// max painter.
  29. /// ||设定的painter数量。
  30. /// </summary>
  31. public int maxPainter
  32. {
  33. get { return m_MaxPainter; }
  34. set { if (PropertyUtil.SetStruct(ref m_MaxPainter, value < 0 ? 1 : value)) SetVerticesDirty(); }
  35. }
  36. /// <summary>
  37. /// Painter是否逆序。逆序时index大的serie最先绘制。
  38. /// </summary>
  39. public bool reversePainter
  40. {
  41. get { return m_ReversePainter; }
  42. set { if (PropertyUtil.SetStruct(ref m_ReversePainter, value)) SetVerticesDirty(); }
  43. }
  44. /// <summary>
  45. /// Base Pointer 材质球,设置后会影响Axis等。
  46. /// </summary>
  47. public Material basePainterMaterial
  48. {
  49. get { return m_BasePainterMaterial; }
  50. set { if (PropertyUtil.SetClass(ref m_BasePainterMaterial, value)) SetComponentDirty(); }
  51. }
  52. /// <summary>
  53. /// Serie Pointer 材质球,设置后会影响所有Serie。
  54. /// </summary>
  55. public Material seriePainterMaterial
  56. {
  57. get { return m_SeriePainterMaterial; }
  58. set { if (PropertyUtil.SetClass(ref m_SeriePainterMaterial, value)) SetComponentDirty(); }
  59. }
  60. /// <summary>
  61. /// Top Pointer 材质球。
  62. /// </summary>
  63. public Material topPainterMaterial
  64. {
  65. get { return m_TopPainterMaterial; }
  66. set { if (PropertyUtil.SetClass(ref m_TopPainterMaterial, value)) SetComponentDirty(); }
  67. }
  68. /// <summary>
  69. /// Upper Pointer 材质球。
  70. /// </summary>
  71. public Material upperPainterMaterial
  72. {
  73. get { return m_UpperPainterMaterial; }
  74. set { if (PropertyUtil.SetClass(ref m_UpperPainterMaterial, value)) SetComponentDirty(); }
  75. }
  76. /// <summary>
  77. /// Curve smoothing factor. By adjusting the smoothing coefficient, the curvature of the curve can be changed,
  78. /// and different curves with slightly different appearance can be obtained.
  79. /// ||曲线平滑系数。通过调整平滑系数可以改变曲线的曲率,得到外观稍微有变化的不同曲线。
  80. /// </summary>
  81. public float lineSmoothStyle
  82. {
  83. get { return m_LineSmoothStyle; }
  84. set { if (PropertyUtil.SetStruct(ref m_LineSmoothStyle, value < 0 ? 1f : value)) SetVerticesDirty(); }
  85. }
  86. /// <summary>
  87. /// Smoothness of curve. The smaller the value, the smoother the curve, but the number of vertices will increase.
  88. /// ||When the area with gradient is filled, the larger the value, the worse the transition effect.
  89. /// ||曲线平滑度。值越小曲线越平滑,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。
  90. /// </summary>
  91. public float lineSmoothness
  92. {
  93. get { return m_LineSmoothness; }
  94. set { if (PropertyUtil.SetStruct(ref m_LineSmoothness, value < 0 ? 1f : value)) SetVerticesDirty(); }
  95. }
  96. /// <summary>
  97. /// The partition distance of a line segment. A line in a normal line chart is made up of many segments,
  98. /// the number of which is determined by the change in value. The smaller the number of segments,
  99. /// the higher the number of vertices. When the area with gradient is filled, the larger the value, the worse the transition effect.
  100. /// ||线段的分割距离。普通折线图的线是由很多线段组成,段数由该数值决定。值越小段数越多,但顶点数也会随之增加。当开启有渐变的区域填充时,数值越大渐变过渡效果越差。
  101. /// </summary>
  102. public float lineSegmentDistance
  103. {
  104. get { return m_LineSegmentDistance; }
  105. set { if (PropertyUtil.SetStruct(ref m_LineSegmentDistance, value < 0 ? 1f : value)) SetVerticesDirty(); }
  106. }
  107. /// <summary>
  108. /// the smoothess of cricle.
  109. /// ||圆形的平滑度。数越小圆越平滑,但顶点数也会随之增加。
  110. /// </summary>
  111. public float cicleSmoothness
  112. {
  113. get { return m_CicleSmoothness; }
  114. set { if (PropertyUtil.SetStruct(ref m_CicleSmoothness, value < 0 ? 1f : value)) SetVerticesDirty(); }
  115. }
  116. /// <summary>
  117. /// the width of line serie legend.
  118. /// ||Line类型图例图标的线条宽度。
  119. /// </summary>
  120. public float legendIconLineWidth
  121. {
  122. get { return m_LegendIconLineWidth; }
  123. set { if (PropertyUtil.SetStruct(ref m_LegendIconLineWidth, value)) SetVerticesDirty(); }
  124. }
  125. /// <summary>
  126. /// The radius of rounded corner. Its unit is px. Use array to respectively specify the 4 corner radiuses((clockwise upper left, upper right, bottom right and bottom left)).
  127. /// ||图例圆角半径。用数组分别指定4个圆角半径(顺时针左上,右上,右下,左下)。
  128. /// </summary>
  129. public float[] legendIconCornerRadius
  130. {
  131. get { return m_LegendIconCornerRadius; }
  132. set { if (PropertyUtil.SetClass(ref m_LegendIconCornerRadius, value, true)) SetVerticesDirty(); }
  133. }
  134. /// <summary>
  135. /// the max splitnumber of axis.
  136. /// ||坐标轴最大分隔段数。段数过大时可能会生成较多的label节点。
  137. /// </summary>
  138. public float axisMaxSplitNumber
  139. {
  140. get { return m_AxisMaxSplitNumber; }
  141. set { if (PropertyUtil.SetStruct(ref m_AxisMaxSplitNumber, value)) SetVerticesDirty(); }
  142. }
  143. public void Copy(Settings settings)
  144. {
  145. m_ReversePainter = settings.reversePainter;
  146. m_MaxPainter = settings.maxPainter;
  147. m_BasePainterMaterial = settings.basePainterMaterial;
  148. m_SeriePainterMaterial = settings.seriePainterMaterial;
  149. m_UpperPainterMaterial = settings.upperPainterMaterial;
  150. m_TopPainterMaterial = settings.topPainterMaterial;
  151. m_LineSmoothStyle = settings.lineSmoothStyle;
  152. m_LineSmoothness = settings.lineSmoothness;
  153. m_LineSegmentDistance = settings.lineSegmentDistance;
  154. m_CicleSmoothness = settings.cicleSmoothness;
  155. m_LegendIconLineWidth = settings.legendIconLineWidth;
  156. ChartHelper.CopyArray(m_LegendIconCornerRadius, settings.legendIconCornerRadius);
  157. }
  158. public override void Reset()
  159. {
  160. Copy(DefaultSettings);
  161. }
  162. public static Settings DefaultSettings
  163. {
  164. get
  165. {
  166. return new Settings()
  167. {
  168. m_ReversePainter = false,
  169. m_MaxPainter = XCSettings.maxPainter,
  170. m_LineSmoothStyle = XCSettings.lineSmoothStyle,
  171. m_LineSmoothness = XCSettings.lineSmoothness,
  172. m_LineSegmentDistance = XCSettings.lineSegmentDistance,
  173. m_CicleSmoothness = XCSettings.cicleSmoothness,
  174. m_LegendIconLineWidth = 2,
  175. m_LegendIconCornerRadius = new float[] { 0.25f, 0.25f, 0.25f, 0.25f }
  176. };
  177. }
  178. }
  179. }
  180. }