From d6a024026bbfcae8adf6f40492fe66dedf4e7048 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sat, 5 Jun 2021 09:56:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E4=B8=BB=E9=A2=98`Theme`=E7=9A=84=E8=87=AA=E5=8A=A8=E5=88=B7?= =?UTF-8?q?=E6=96=B0=20(#148)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG-EN.md | 1 + CHANGELOG.md | 1 + Editor/Utility/ThemeCheck.cs | 7 +++++++ Runtime/Mgr/XThemeMgr.cs | 8 ++++++++ 4 files changed, 17 insertions(+) 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);