优化Theme

This commit is contained in:
monitor1394
2021-04-01 12:13:51 +08:00
parent 9c96fbb604
commit d423ad6c9e
3 changed files with 6 additions and 2 deletions

View File

@@ -25,6 +25,8 @@ namespace XCharts
{
if (!IsThemeAsset(assetPath)) return;
var obj = AssetDatabase.LoadAssetAtPath<TextAsset>(assetPath);
if (obj == null || obj.text == null) return;
if (!obj.text.Contains("m_Theme")) return;
if (XChartsSettings.AddJsonTheme(obj))
{
XThemeMgr.ReloadThemeList();
@@ -54,6 +56,7 @@ namespace XCharts
private static bool IsThemeAsset(string assetPath)
{
if (!assetPath.EndsWith(".json")) return false;
if (!assetPath.StartsWith("XTheme")) return false;
return true;
}
}

View File

@@ -25,7 +25,7 @@ namespace XCharts
AddTheme(ChartTheme.Dark);
foreach (var json in XChartsSettings.customThemes)
{
if (json != null)
if (json != null && !string.IsNullOrEmpty(json.text))
{
var theme = JsonUtility.FromJson<ChartTheme>(json.text);
AddTheme(theme);
@@ -36,6 +36,7 @@ namespace XCharts
public static void AddTheme(ChartTheme theme)
{
if (theme == null) return;
if (!XChartsMgr.Instance.m_ThemeDict.ContainsKey(theme.themeName))
{
XChartsMgr.Instance.m_ThemeDict.Add(theme.themeName, theme);

View File

@@ -152,7 +152,7 @@ namespace XCharts
public static bool AddJsonTheme(TextAsset theme)
{
if (theme == null) return false;
if (theme == null || string.IsNullOrEmpty(theme.text)) return false;
if (!Instance.m_CustomThemes.Contains(theme))
{
Instance.m_CustomThemes.Add(theme);