Painter.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /************************************************/
  2. /* */
  3. /* Copyright (c) 2018 - 2021 monitor1394 */
  4. /* https://github.com/monitor1394 */
  5. /* */
  6. /************************************************/
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. using System;
  10. namespace XCharts
  11. {
  12. [RequireComponent(typeof(CanvasRenderer))]
  13. public class Painter : MaskableGraphic
  14. {
  15. public enum Type
  16. {
  17. Base,
  18. Serie,
  19. Top
  20. }
  21. protected int m_Index = -1;
  22. protected Type m_Type = Type.Base;
  23. protected bool m_Refresh;
  24. protected Action<VertexHelper, Painter> m_OnPopulateMesh;
  25. public Action<VertexHelper, Painter> onPopulateMesh { set { m_OnPopulateMesh = value; } }
  26. public int index { get { return m_Index; } set { m_Index = value; } }
  27. public Type type { get { return m_Type; } set { m_Type = value; } }
  28. public void Refresh()
  29. {
  30. if (gameObject == null) return;
  31. if (!gameObject.activeSelf) return;
  32. m_Refresh = true;
  33. }
  34. public void Init()
  35. {
  36. raycastTarget = false;
  37. }
  38. public void SetActive(bool flag, bool isDebugMode = false)
  39. {
  40. if (gameObject.activeInHierarchy != flag)
  41. {
  42. gameObject.SetActive(flag);
  43. }
  44. var hideFlags = flag && isDebugMode ? HideFlags.None : HideFlags.HideInHierarchy;
  45. if (gameObject.hideFlags != hideFlags)
  46. {
  47. gameObject.hideFlags = hideFlags;
  48. }
  49. }
  50. protected override void Awake()
  51. {
  52. Init();
  53. }
  54. internal void CheckRefresh()
  55. {
  56. if (m_Refresh && gameObject.activeSelf)
  57. {
  58. m_Refresh = false;
  59. SetVerticesDirty();
  60. }
  61. }
  62. protected override void OnPopulateMesh(VertexHelper vh)
  63. {
  64. vh.Clear();
  65. if (m_OnPopulateMesh != null)
  66. {
  67. m_OnPopulateMesh(vh, this);
  68. }
  69. }
  70. }
  71. }