2020-07-10 09:36:56 +08:00
|
|
|
using System.Collections.Generic;
|
2022-05-22 22:17:38 +08:00
|
|
|
using System.IO;
|
2020-07-10 09:36:56 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
2023-01-30 19:48:59 +08:00
|
|
|
using System.Linq;
|
2021-01-11 08:54:28 +08:00
|
|
|
#if UNITY_EDITOR
|
2023-01-30 19:48:59 +08:00
|
|
|
using ADB = UnityEditor.AssetDatabase;
|
2021-01-11 08:54:28 +08:00
|
|
|
#endif
|
2020-07-10 09:36:56 +08:00
|
|
|
|
2022-02-19 22:37:57 +08:00
|
|
|
namespace XCharts.Runtime
|
2020-07-10 09:36:56 +08:00
|
|
|
{
|
|
|
|
|
class XChartsVersion
|
|
|
|
|
{
|
|
|
|
|
public string version = "";
|
|
|
|
|
public int date = 0;
|
|
|
|
|
public int checkdate = 0;
|
|
|
|
|
public string desc = "";
|
|
|
|
|
public string homepage = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ExecuteInEditMode]
|
2021-11-23 13:20:07 +08:00
|
|
|
public static class XChartsMgr
|
2020-07-10 09:36:56 +08:00
|
|
|
{
|
2024-06-11 08:28:46 +08:00
|
|
|
public static readonly string version = "3.11.0-preview2";
|
|
|
|
|
public static readonly int versionDate = 20240611;
|
2021-01-19 12:39:12 +08:00
|
|
|
public static string fullVersion { get { return version + "-" + versionDate; } }
|
2020-07-10 09:36:56 +08:00
|
|
|
|
2021-11-23 13:20:07 +08:00
|
|
|
internal static List<BaseChart> chartList = new List<BaseChart>();
|
|
|
|
|
internal static Dictionary<string, Theme> themes = new Dictionary<string, Theme>();
|
|
|
|
|
internal static List<string> themeNames = new List<string>();
|
2020-07-10 09:36:56 +08:00
|
|
|
|
2021-11-23 13:20:07 +08:00
|
|
|
static XChartsMgr()
|
2020-07-10 09:36:56 +08:00
|
|
|
{
|
|
|
|
|
SerieLabelPool.ClearAll();
|
2021-11-23 13:20:07 +08:00
|
|
|
chartList.Clear();
|
2022-02-25 08:10:09 +08:00
|
|
|
if (Resources.Load<XCSettings>("XCSettings"))
|
2021-11-23 13:20:07 +08:00
|
|
|
XCThemeMgr.ReloadThemeList();
|
2020-07-10 09:36:56 +08:00
|
|
|
SceneManager.sceneUnloaded += OnSceneLoaded;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 13:20:07 +08:00
|
|
|
static void OnSceneLoaded(Scene scene)
|
2020-07-10 09:36:56 +08:00
|
|
|
{
|
|
|
|
|
SerieLabelPool.ClearAll();
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 13:20:07 +08:00
|
|
|
public static void AddChart(BaseChart chart)
|
2020-07-10 09:36:56 +08:00
|
|
|
{
|
|
|
|
|
var sameNameChart = GetChart(chart.chartName);
|
|
|
|
|
if (sameNameChart != null)
|
|
|
|
|
{
|
|
|
|
|
var path = ChartHelper.GetFullName(sameNameChart.transform);
|
|
|
|
|
Debug.LogError("A chart named `" + chart.chartName + "` already exists:" + path);
|
2021-11-23 13:20:07 +08:00
|
|
|
RemoveChart(chart.chartName);
|
2020-07-10 09:36:56 +08:00
|
|
|
}
|
|
|
|
|
if (!ContainsChart(chart))
|
|
|
|
|
{
|
2021-11-23 13:20:07 +08:00
|
|
|
chartList.Add(chart);
|
2020-07-10 09:36:56 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 13:20:07 +08:00
|
|
|
public static BaseChart GetChart(string chartName)
|
2020-07-10 09:36:56 +08:00
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(chartName)) return null;
|
2021-11-23 13:20:07 +08:00
|
|
|
return chartList.Find(chart => chartName.Equals(chart.chartName));
|
2020-07-10 09:36:56 +08:00
|
|
|
}
|
|
|
|
|
|
2021-11-23 13:20:07 +08:00
|
|
|
public static List<BaseChart> GetCharts(string chartName)
|
2020-07-10 09:36:56 +08:00
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(chartName)) return null;
|
2022-02-25 08:10:09 +08:00
|
|
|
return chartList.FindAll(chart => chartName.Equals(chart.chartName));
|
2020-07-10 09:36:56 +08:00
|
|
|
}
|
|
|
|
|
|
2021-11-23 13:20:07 +08:00
|
|
|
public static void RemoveChart(string chartName)
|
2020-07-10 09:36:56 +08:00
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(chartName)) return;
|
2021-11-23 13:20:07 +08:00
|
|
|
chartList.RemoveAll(chart => chartName.Equals(chart.chartName));
|
2020-07-10 09:36:56 +08:00
|
|
|
}
|
|
|
|
|
|
2021-11-23 13:20:07 +08:00
|
|
|
public static bool ContainsChart(string chartName)
|
2020-07-10 09:36:56 +08:00
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(chartName)) return false;
|
2023-02-01 21:00:37 +08:00
|
|
|
var list = GetCharts(chartName);
|
|
|
|
|
return list != null && list.Count > 0;
|
2020-07-10 09:36:56 +08:00
|
|
|
}
|
|
|
|
|
|
2021-11-23 13:20:07 +08:00
|
|
|
public static bool ContainsChart(BaseChart chart)
|
2020-07-10 09:36:56 +08:00
|
|
|
{
|
2021-11-23 13:20:07 +08:00
|
|
|
return chartList.Contains(chart);
|
2020-07-10 09:36:56 +08:00
|
|
|
}
|
2021-01-11 08:54:28 +08:00
|
|
|
|
2022-03-29 22:06:10 +08:00
|
|
|
public static bool IsRepeatChartName(BaseChart chart, string chartName = null)
|
|
|
|
|
{
|
|
|
|
|
if (chartName == null)
|
|
|
|
|
chartName = chart.chartName;
|
|
|
|
|
if (string.IsNullOrEmpty(chartName))
|
|
|
|
|
return false;
|
|
|
|
|
foreach (var temp in chartList)
|
|
|
|
|
{
|
|
|
|
|
if (temp != chart && chartName.Equals(temp.chartName))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetRepeatChartNameInfo(BaseChart chart, string chartName)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(chartName))
|
|
|
|
|
return string.Empty;
|
|
|
|
|
string result = "";
|
|
|
|
|
foreach (var temp in chartList)
|
|
|
|
|
{
|
|
|
|
|
if (temp != chart && chartName.Equals(temp.chartName))
|
|
|
|
|
result += ChartHelper.GetFullName(temp.transform) + "\n";
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-11 08:54:28 +08:00
|
|
|
public static void RemoveAllChartObject()
|
|
|
|
|
{
|
2021-11-23 13:20:07 +08:00
|
|
|
if (chartList.Count == 0)
|
2021-01-11 08:54:28 +08:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-11-23 13:20:07 +08:00
|
|
|
foreach (var chart in chartList)
|
2021-01-11 08:54:28 +08:00
|
|
|
{
|
|
|
|
|
if (chart != null)
|
2022-03-09 07:26:15 +08:00
|
|
|
chart.RebuildChartObject();
|
2021-01-11 08:54:28 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 08:17:54 +08:00
|
|
|
#if UNITY_EDITOR
|
2023-01-30 19:48:59 +08:00
|
|
|
|
2021-02-27 05:01:26 +08:00
|
|
|
public static string GetPackageFullPath()
|
|
|
|
|
{
|
|
|
|
|
string packagePath = Path.GetFullPath("Packages/com.monitor1394.xcharts");
|
|
|
|
|
if (Directory.Exists(packagePath))
|
|
|
|
|
{
|
|
|
|
|
return packagePath;
|
|
|
|
|
}
|
2023-01-30 19:48:59 +08:00
|
|
|
packagePath = ADB.FindAssets("t:Script")
|
|
|
|
|
.Where(v => Path.GetFileNameWithoutExtension(ADB.GUIDToAssetPath(v)) == "XChartsMgr")
|
|
|
|
|
.Select(id => ADB.GUIDToAssetPath(id))
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
packagePath = Path.GetDirectoryName(packagePath);
|
|
|
|
|
packagePath = packagePath.Substring(0, packagePath.LastIndexOf("Runtime"));
|
|
|
|
|
return packagePath;
|
2021-02-27 05:01:26 +08:00
|
|
|
}
|
|
|
|
|
|
2021-11-23 13:20:07 +08:00
|
|
|
[UnityEditor.Callbacks.DidReloadScripts]
|
|
|
|
|
static void OnEditorReload()
|
|
|
|
|
{
|
|
|
|
|
for (int i = chartList.Count - 1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
var chart = chartList[i];
|
|
|
|
|
if (chart == null)
|
|
|
|
|
{
|
|
|
|
|
chartList.RemoveAt(i);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
chart.InitComponentHandlers();
|
|
|
|
|
chart.InitSerieHandlers();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-21 12:34:48 +08:00
|
|
|
#endif
|
2020-07-10 09:36:56 +08:00
|
|
|
}
|
|
|
|
|
}
|