SymbolStyle.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace XCharts.Runtime
  5. {
  6. /// <summary>
  7. /// the type of symbol.
  8. /// ||标记图形的类型。
  9. /// </summary>
  10. public enum SymbolType
  11. {
  12. /// <summary>
  13. /// 不显示标记。
  14. /// </summary>
  15. None,
  16. /// <summary>
  17. /// 自定义标记。
  18. /// </summary>
  19. Custom,
  20. /// <summary>
  21. /// 圆形。
  22. /// </summary>
  23. Circle,
  24. /// <summary>
  25. /// 空心圆。
  26. /// </summary>
  27. EmptyCircle,
  28. /// <summary>
  29. /// 正方形。可通过设置`itemStyle`的`cornerRadius`变成圆角矩形。
  30. /// </summary>
  31. Rect,
  32. /// <summary>
  33. /// 空心正方形。
  34. /// </summary>
  35. EmptyRect,
  36. /// <summary>
  37. /// 三角形。
  38. /// </summary>
  39. Triangle,
  40. /// <summary>
  41. /// 空心三角形。
  42. /// </summary>
  43. EmptyTriangle,
  44. /// <summary>
  45. /// 菱形。
  46. /// </summary>
  47. Diamond,
  48. /// <summary>
  49. /// 空心菱形。
  50. /// </summary>
  51. EmptyDiamond,
  52. /// <summary>
  53. /// 箭头。
  54. /// </summary>
  55. Arrow,
  56. /// <summary>
  57. /// 空心箭头。
  58. /// </summary>
  59. EmptyArrow,
  60. /// <summary>
  61. /// 加号。
  62. /// </summary>
  63. Plus,
  64. /// <summary>
  65. /// 减号。
  66. /// </summary>
  67. Minus,
  68. }
  69. /// <summary>
  70. /// 系列数据项的标记的图形
  71. /// </summary>
  72. [System.Serializable]
  73. public class SymbolStyle : ChildComponent
  74. {
  75. [SerializeField] protected bool m_Show = true;
  76. [SerializeField] protected SymbolType m_Type = SymbolType.EmptyCircle;
  77. [SerializeField] protected float m_Size = 0f;
  78. [SerializeField] protected float m_Gap = 0;
  79. [SerializeField] protected float m_Width = 0f;
  80. [SerializeField] protected float m_Height = 0f;
  81. [SerializeField] protected Vector2 m_Offset = Vector2.zero;
  82. [SerializeField] protected Sprite m_Image;
  83. [SerializeField] protected Image.Type m_ImageType;
  84. [SerializeField] protected Color32 m_Color;
  85. public virtual void Reset()
  86. {
  87. m_Show = false;
  88. m_Type = SymbolType.EmptyCircle;
  89. m_Size = 0f;
  90. m_Gap = 0;
  91. m_Width = 0f;
  92. m_Height = 0f;
  93. m_Offset = Vector2.zero;
  94. m_Image = null;
  95. m_ImageType = Image.Type.Simple;
  96. }
  97. /// <summary>
  98. /// Whether the symbol is showed.
  99. /// ||是否显示标记。
  100. /// </summary>
  101. public bool show
  102. {
  103. get { return m_Show; }
  104. set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetAllDirty(); }
  105. }
  106. /// <summary>
  107. /// the type of symbol.
  108. /// ||标记类型。
  109. /// </summary>
  110. public SymbolType type
  111. {
  112. get { return m_Type; }
  113. set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetVerticesDirty(); }
  114. }
  115. /// <summary>
  116. /// the size of symbol.
  117. /// ||标记的大小。
  118. /// </summary>
  119. public float size
  120. {
  121. get { return m_Size; }
  122. set { if (PropertyUtil.SetStruct(ref m_Size, value)) SetVerticesDirty(); }
  123. }
  124. /// <summary>
  125. /// the gap of symbol and line segment.
  126. /// ||图形标记和线条的间隙距离。
  127. /// </summary>
  128. public float gap
  129. {
  130. get { return m_Gap; }
  131. set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetVerticesDirty(); }
  132. }
  133. /// <summary>
  134. /// 图形的宽。
  135. /// </summary>
  136. public float width
  137. {
  138. get { return m_Width; }
  139. set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetAllDirty(); }
  140. }
  141. /// <summary>
  142. /// 图形的高。
  143. /// </summary>
  144. public float height
  145. {
  146. get { return m_Height; }
  147. set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetAllDirty(); }
  148. }
  149. /// <summary>
  150. /// 自定义的标记图形。
  151. /// </summary>
  152. public Sprite image
  153. {
  154. get { return m_Image; }
  155. set { if (PropertyUtil.SetClass(ref m_Image, value)) SetAllDirty(); }
  156. }
  157. /// <summary>
  158. /// the fill type of image.
  159. /// ||图形填充类型。
  160. /// </summary>
  161. public Image.Type imageType
  162. {
  163. get { return m_ImageType; }
  164. set { if (PropertyUtil.SetStruct(ref m_ImageType, value)) SetAllDirty(); }
  165. }
  166. /// <summary>
  167. /// 图形的偏移。
  168. /// </summary>
  169. public Vector2 offset
  170. {
  171. get { return m_Offset; }
  172. set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetAllDirty(); }
  173. }
  174. /// <summary>
  175. /// 图形的颜色。
  176. /// </summary>
  177. public Color32 color
  178. {
  179. get { return m_Color; }
  180. set { if (PropertyUtil.SetStruct(ref m_Color, value)) SetAllDirty(); }
  181. }
  182. public Vector3 offset3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } }
  183. private List<float> m_AnimationSize = new List<float>() { 0, 5, 10 };
  184. /// <summary>
  185. /// the setting for effect scatter.
  186. /// ||带有涟漪特效动画的散点图的动画参数。
  187. /// </summary>
  188. public List<float> animationSize { get { return m_AnimationSize; } }
  189. public Color32 GetColor(Color32 defaultColor)
  190. {
  191. return ChartHelper.IsClearColor(m_Color) ? defaultColor : m_Color;
  192. }
  193. }
  194. }