Bez popisu
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.

MainComponent.cs 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System;
  2. using System.Text;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using UnityEngine.UI;
  6. namespace XCharts.Runtime
  7. {
  8. [System.Serializable]
  9. public class MainComponent : IComparable
  10. {
  11. public int instanceId { get { return index; } }
  12. public int index { get; internal set; }
  13. protected bool m_VertsDirty;
  14. protected bool m_ComponentDirty;
  15. protected Painter m_Painter;
  16. /// <summary>
  17. /// 图表重绘标记。
  18. /// </summary>
  19. public virtual bool vertsDirty { get { return m_VertsDirty; } }
  20. /// <summary>
  21. /// 组件重新初始化标记。
  22. /// </summary>
  23. public virtual bool componentDirty { get { return m_ComponentDirty; } }
  24. /// <summary>
  25. /// 需要重绘图表或重新初始化组件。
  26. /// </summary>
  27. public bool anyDirty { get { return vertsDirty || componentDirty; } }
  28. public Painter painter { get { return m_Painter; } set { m_Painter = value; } }
  29. public Action refreshComponent { get; set; }
  30. public GameObject gameObject { get; set; }
  31. internal MainComponentHandler handler { get; set; }
  32. public virtual void SetVerticesDirty()
  33. {
  34. m_VertsDirty = true;
  35. }
  36. public virtual void ClearVerticesDirty()
  37. {
  38. m_VertsDirty = false;
  39. }
  40. public virtual void SetComponentDirty()
  41. {
  42. m_ComponentDirty = true;
  43. }
  44. public virtual void ClearComponentDirty()
  45. {
  46. m_ComponentDirty = false;
  47. }
  48. public virtual void Reset() { }
  49. public virtual void ClearData() { }
  50. public virtual void ClearDirty()
  51. {
  52. ClearVerticesDirty();
  53. ClearComponentDirty();
  54. }
  55. public virtual void SetAllDirty()
  56. {
  57. SetVerticesDirty();
  58. SetComponentDirty();
  59. }
  60. public virtual void SetDefaultValue() { }
  61. public virtual void OnRemove()
  62. {
  63. if (handler != null)
  64. handler.RemoveComponent();
  65. }
  66. public int CompareTo(object obj)
  67. {
  68. var flag = GetType().Name.CompareTo(obj.GetType().Name);
  69. if (flag == 0)
  70. return index.CompareTo((obj as MainComponent).index);
  71. else
  72. return flag;
  73. }
  74. }
  75. public abstract class MainComponentHandler
  76. {
  77. public BaseChart chart { get; internal set; }
  78. public ComponentHandlerAttribute attribute { get; internal set; }
  79. public virtual void InitComponent() { }
  80. public virtual void RemoveComponent() { }
  81. public virtual void CheckComponent(StringBuilder sb) { }
  82. public virtual void Update() { }
  83. public virtual void DrawBase(VertexHelper vh) { }
  84. public virtual void DrawUpper(VertexHelper vh) { }
  85. public virtual void DrawTop(VertexHelper vh) { }
  86. public virtual void OnSerieDataUpdate(int serieIndex) { }
  87. public virtual void OnPointerClick(PointerEventData eventData) { }
  88. public virtual void OnPointerDown(PointerEventData eventData) { }
  89. public virtual void OnPointerUp(PointerEventData eventData) { }
  90. public virtual void OnPointerEnter(PointerEventData eventData) { }
  91. public virtual void OnPointerExit(PointerEventData eventData) { }
  92. public virtual void OnDrag(PointerEventData eventData) { }
  93. public virtual void OnBeginDrag(PointerEventData eventData) { }
  94. public virtual void OnEndDrag(PointerEventData eventData) { }
  95. public virtual void OnScroll(PointerEventData eventData) { }
  96. internal abstract void SetComponent(MainComponent component);
  97. }
  98. public abstract class MainComponentHandler<T> : MainComponentHandler
  99. where T : MainComponent
  100. {
  101. public T component { get; internal set; }
  102. internal override void SetComponent(MainComponent component)
  103. {
  104. this.component = (T) component;
  105. }
  106. }
  107. }