暫無描述
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.

UIHelper.cs 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using XUGL;
  6. namespace XCharts.Runtime
  7. {
  8. /// <summary>
  9. /// UI帮助类。
  10. /// </summary>
  11. public static class UIHelper
  12. {
  13. internal static void DrawBackground(VertexHelper vh, UIComponent component)
  14. {
  15. if (component.background.show == false ||
  16. (component.background.sprite == null && ChartHelper.IsClearColor(component.background.color)))
  17. {
  18. var p1 = new Vector3(component.graphX, component.graphY);
  19. var p2 = new Vector3(component.graphX + component.graphWidth, component.graphY);
  20. var p3 = new Vector3(component.graphX + component.graphWidth, component.graphY + component.graphHeight);
  21. var p4 = new Vector3(component.graphX, component.graphY + component.graphHeight);
  22. UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, GetBackgroundColor(component));
  23. }
  24. }
  25. internal static void InitBackground(UIComponent table)
  26. {
  27. if (table.background.show == false ||
  28. (table.background.sprite == null && ChartHelper.IsClearColor(table.background.color)))
  29. {
  30. ChartHelper.DestoryGameObject(table.transform, "Background");
  31. return;
  32. }
  33. var sizeDelta = table.background.width > 0 && table.background.height > 0 ?
  34. new Vector2(table.background.width, table.background.height) :
  35. table.graphSizeDelta;
  36. var backgroundObj = ChartHelper.AddObject("Background", table.transform, table.graphMinAnchor,
  37. table.graphMaxAnchor, table.graphPivot, sizeDelta);
  38. backgroundObj.hideFlags = table.chartHideFlags;
  39. var backgroundImage = ChartHelper.EnsureComponent<Image>(backgroundObj);
  40. ChartHelper.UpdateRectTransform(backgroundObj, table.graphMinAnchor,
  41. table.graphMaxAnchor, table.graphPivot, sizeDelta);
  42. ChartHelper.SetBackground(backgroundImage, table.background);
  43. backgroundObj.transform.SetSiblingIndex(0);
  44. }
  45. public static Color32 GetBackgroundColor(UIComponent component)
  46. {
  47. if (component.background.show && !ChartHelper.IsClearColor(component.background.color))
  48. return component.background.color;
  49. else
  50. return component.theme.backgroundColor;
  51. }
  52. }
  53. }