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

XChartsMgr.cs 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using System.Linq;
  6. #if UNITY_EDITOR
  7. using ADB = UnityEditor.AssetDatabase;
  8. #endif
  9. namespace XCharts.Runtime
  10. {
  11. class XChartsVersion
  12. {
  13. public string version = "";
  14. public int date = 0;
  15. public int checkdate = 0;
  16. public string desc = "";
  17. public string homepage = "";
  18. }
  19. [ExecuteInEditMode]
  20. public static class XChartsMgr
  21. {
  22. public static readonly string version = "3.6.0";
  23. public static readonly int versionDate = 20230201;
  24. public static string fullVersion { get { return version + "-" + versionDate; } }
  25. internal static List<BaseChart> chartList = new List<BaseChart>();
  26. internal static Dictionary<string, Theme> themes = new Dictionary<string, Theme>();
  27. internal static List<string> themeNames = new List<string>();
  28. static XChartsMgr()
  29. {
  30. SerieLabelPool.ClearAll();
  31. chartList.Clear();
  32. if (Resources.Load<XCSettings>("XCSettings"))
  33. XCThemeMgr.ReloadThemeList();
  34. SceneManager.sceneUnloaded += OnSceneLoaded;
  35. }
  36. static void OnSceneLoaded(Scene scene)
  37. {
  38. SerieLabelPool.ClearAll();
  39. }
  40. public static void AddChart(BaseChart chart)
  41. {
  42. var sameNameChart = GetChart(chart.chartName);
  43. if (sameNameChart != null)
  44. {
  45. var path = ChartHelper.GetFullName(sameNameChart.transform);
  46. Debug.LogError("A chart named `" + chart.chartName + "` already exists:" + path);
  47. RemoveChart(chart.chartName);
  48. }
  49. if (!ContainsChart(chart))
  50. {
  51. chartList.Add(chart);
  52. }
  53. }
  54. public static BaseChart GetChart(string chartName)
  55. {
  56. if (string.IsNullOrEmpty(chartName)) return null;
  57. return chartList.Find(chart => chartName.Equals(chart.chartName));
  58. }
  59. public static List<BaseChart> GetCharts(string chartName)
  60. {
  61. if (string.IsNullOrEmpty(chartName)) return null;
  62. return chartList.FindAll(chart => chartName.Equals(chart.chartName));
  63. }
  64. public static void RemoveChart(string chartName)
  65. {
  66. if (string.IsNullOrEmpty(chartName)) return;
  67. chartList.RemoveAll(chart => chartName.Equals(chart.chartName));
  68. }
  69. public static bool ContainsChart(string chartName)
  70. {
  71. if (string.IsNullOrEmpty(chartName)) return false;
  72. var list = GetCharts(chartName);
  73. return list != null && list.Count > 0;
  74. }
  75. public static bool ContainsChart(BaseChart chart)
  76. {
  77. return chartList.Contains(chart);
  78. }
  79. public static bool IsRepeatChartName(BaseChart chart, string chartName = null)
  80. {
  81. if (chartName == null)
  82. chartName = chart.chartName;
  83. if (string.IsNullOrEmpty(chartName))
  84. return false;
  85. foreach (var temp in chartList)
  86. {
  87. if (temp != chart && chartName.Equals(temp.chartName))
  88. return true;
  89. }
  90. return false;
  91. }
  92. public static string GetRepeatChartNameInfo(BaseChart chart, string chartName)
  93. {
  94. if (string.IsNullOrEmpty(chartName))
  95. return string.Empty;
  96. string result = "";
  97. foreach (var temp in chartList)
  98. {
  99. if (temp != chart && chartName.Equals(temp.chartName))
  100. result += ChartHelper.GetFullName(temp.transform) + "\n";
  101. }
  102. return result;
  103. }
  104. public static void RemoveAllChartObject()
  105. {
  106. if (chartList.Count == 0)
  107. {
  108. return;
  109. }
  110. foreach (var chart in chartList)
  111. {
  112. if (chart != null)
  113. chart.RebuildChartObject();
  114. }
  115. }
  116. #if UNITY_EDITOR
  117. public static string GetPackageFullPath()
  118. {
  119. string packagePath = Path.GetFullPath("Packages/com.monitor1394.xcharts");
  120. if (Directory.Exists(packagePath))
  121. {
  122. return packagePath;
  123. }
  124. packagePath = ADB.FindAssets("t:Script")
  125. .Where(v => Path.GetFileNameWithoutExtension(ADB.GUIDToAssetPath(v)) == "XChartsMgr")
  126. .Select(id => ADB.GUIDToAssetPath(id))
  127. .FirstOrDefault();
  128. packagePath = Path.GetDirectoryName(packagePath);
  129. packagePath = packagePath.Substring(0, packagePath.LastIndexOf("Runtime"));
  130. return packagePath;
  131. }
  132. [UnityEditor.Callbacks.DidReloadScripts]
  133. static void OnEditorReload()
  134. {
  135. for (int i = chartList.Count - 1; i >= 0; i--)
  136. {
  137. var chart = chartList[i];
  138. if (chart == null)
  139. {
  140. chartList.RemoveAt(i);
  141. }
  142. else
  143. {
  144. chart.InitComponentHandlers();
  145. chart.InitSerieHandlers();
  146. }
  147. }
  148. }
  149. #endif
  150. }
  151. }