diff --git a/CHANGELOG-EN.md b/CHANGELOG-EN.md index e24a122c..3c856060 100644 --- a/CHANGELOG-EN.md +++ b/CHANGELOG-EN.md @@ -35,6 +35,7 @@ ## master +* (2021.06.04) Optimized auto-refresh of custom `Theme` (#148) * (2021.06.04) Fixed `Gauge` having an abnormal pointer position when the minimum value is negative ## v2.2.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index fae6ead8..a78125f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ ## master +* (2021.06.04) 优化自定义主题`Theme`的自动刷新 (#148) * (2021.06.04) 修复`Gauge`在最小值为负数时指针指示位置异常的问题 ## v2.2.0 diff --git a/Editor/Utility/ThemeCheck.cs b/Editor/Utility/ThemeCheck.cs index e3ce8618..f2a49510 100644 --- a/Editor/Utility/ThemeCheck.cs +++ b/Editor/Utility/ThemeCheck.cs @@ -1,3 +1,4 @@ +using System.IO; using UnityEditor; using UnityEngine; @@ -23,6 +24,12 @@ namespace XCharts public static void CheckAddedAsset(string assetPath) { + var fileName = Path.GetFileName(assetPath); + if (fileName.Equals("XChartsSettings.asset")) + { + XThemeMgr.ReloadThemeList(); + return; + } if (!IsThemeAsset(assetPath)) return; var obj = AssetDatabase.LoadAssetAtPath(assetPath); if (obj == null || obj.text == null) return; diff --git a/Runtime/Mgr/XThemeMgr.cs b/Runtime/Mgr/XThemeMgr.cs index c702f9b8..61b286ec 100644 --- a/Runtime/Mgr/XThemeMgr.cs +++ b/Runtime/Mgr/XThemeMgr.cs @@ -94,6 +94,14 @@ namespace XCharts newtheme.theme = Theme.Custom; newtheme.themeName = themeNewName; + if (!Directory.Exists(Application.dataPath + "/XCharts")) + { + Directory.CreateDirectory(Application.dataPath + "/XCharts"); + } + if (!Directory.Exists(Application.dataPath + "/XCharts/Resources")) + { + Directory.CreateDirectory(Application.dataPath + "/XCharts/Resources"); + } var themeFileName = "XTheme-" + newtheme.themeName; var assetPath = string.Format("Assets/XCharts/Resources/{0}", themeFileName); var filePath = string.Format("{0}/../{1}.json", Application.dataPath, assetPath);