From 0c187b6ff94aab069106d5fc4ac2d648d8a13289 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Mon, 14 Aug 2023 21:57:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D`XCharts`=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E5=BC=80=E5=90=AF`TextMeshPro`=E5=92=8C=20`NewInputSystem`?= =?UTF-8?q?=E5=90=8E=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC=E4=BC=9A=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98=20(#272)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation~/zh/changelog.md | 7 +- .../{ThemeCheck.cs => XChartsDaemon.cs} | 33 ++++++-- ...emeCheck.cs.meta => XChartsDaemon.cs.meta} | 2 +- Editor/Windows/XChartsEditor.cs | 78 ++++++++++++++----- Editor/XCharts.Editor.asmdef | 4 +- Examples/Example01_RandomData.cs | 2 +- Plugins/Editor.meta | 8 ++ Runtime/Internal/Utilities/ChartHelper.cs | 2 +- Runtime/XCharts.Runtime.asmdef | 5 +- 9 files changed, 109 insertions(+), 32 deletions(-) rename Editor/Utilities/{ThemeCheck.cs => XChartsDaemon.cs} (68%) rename Editor/Utilities/{ThemeCheck.cs.meta => XChartsDaemon.cs.meta} (83%) create mode 100644 Plugins/Editor.meta diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index c352f1fb..ee84a156 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -69,13 +69,16 @@ slug: /changelog 版本要点: -* 重构和完善动画系统,增加`新增动画`和`交互动画`的支持 +* 重构`Animation`动画系统,增加`新增动画`和`交互动画`的支持 * 完善`PieChart`的动画交互表现 * 增加`Symbol`的`EmptyTriangle`、`EmptyDiamond`、`Plus`、`Minus`四种新标记 -* 完善图表的交互回调 +* 完善`Chart`的鼠标交互回调 +* 增加`LabelLine`可固定横坐标的功能 +* 修复千年老问题:开启TMP后更新版本会报错的问题 日志详情: +* (2023.08.14) 修复`XCharts`本地开启`TextMeshPro`和 `NewInputSystem`后更新版本会报错的问题 (#272) * (2023.08.12) 修复`Chart`在运行时被删除时会异常报错的问题 (#269) * (2023.08.11) 修复`DataZoom`开启时可能会导致无法添加数据的问题 * (2023.08.11) 修复`SerieData`单独设置`ItemStyle`的`itemFormatter`不生效的问题 diff --git a/Editor/Utilities/ThemeCheck.cs b/Editor/Utilities/XChartsDaemon.cs similarity index 68% rename from Editor/Utilities/ThemeCheck.cs rename to Editor/Utilities/XChartsDaemon.cs index bb31b353..6b3b3224 100644 --- a/Editor/Utilities/ThemeCheck.cs +++ b/Editor/Utilities/XChartsDaemon.cs @@ -5,9 +5,9 @@ using XCharts.Runtime; namespace XCharts.Editor { - internal static class ThemeCheck + internal static class XChartsDaemon { - public class ThemeAssetPostprocessor : AssetPostprocessor + public class XChartsAssetPostprocessor : AssetPostprocessor { static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetsPaths) @@ -28,17 +28,36 @@ namespace XCharts.Editor var fileName = Path.GetFileName(assetPath); if (fileName.Equals("XCSettings.asset")) { + CheckAsmdef(); XCThemeMgr.ReloadThemeList(); - return; } - if (!IsThemeAsset(assetPath)) return; - var theme = AssetDatabase.LoadAssetAtPath(assetPath); - if (XCSettings.AddCustomTheme(theme)) + else if (IsThemeAsset(assetPath)) { - XCThemeMgr.ReloadThemeList(); + var theme = AssetDatabase.LoadAssetAtPath(assetPath); + if (XCSettings.AddCustomTheme(theme)) + { + XCThemeMgr.ReloadThemeList(); + } } } + public static void CheckAsmdef() + { +#if UNITY_2017_1_OR_NEWER +#if dUI_TextMeshPro + XChartsEditor.CheckAsmdefTmpReference(true); +#else + XChartsEditor.CheckAsmdefTmpReference(false); +#endif +#elif UNITY_2019_1_OR_NEWER +#if INPUT_SYSTEM_ENABLED + XChartsEditor.CheckAsmdefInputSystemReference(true); +#else + XChartsEditor.CheckAsmdefInputSystemReference(false); +#endif +#endif + } + public static void CheckDeletedAsset(string assetPath) { if (!IsThemeAsset(assetPath)) return; diff --git a/Editor/Utilities/ThemeCheck.cs.meta b/Editor/Utilities/XChartsDaemon.cs.meta similarity index 83% rename from Editor/Utilities/ThemeCheck.cs.meta rename to Editor/Utilities/XChartsDaemon.cs.meta index 17375c18..3841cc58 100644 --- a/Editor/Utilities/ThemeCheck.cs.meta +++ b/Editor/Utilities/XChartsDaemon.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4b4ba2a9503ae46b1b7b1ae94ec59127 +guid: 036a714dab7744d76849114f5bcf59a9 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Editor/Windows/XChartsEditor.cs b/Editor/Windows/XChartsEditor.cs index 99ed4adc..7443400f 100644 --- a/Editor/Windows/XChartsEditor.cs +++ b/Editor/Windows/XChartsEditor.cs @@ -199,7 +199,9 @@ namespace XCharts.Editor const string SYMBOL_TMP = "dUI_TextMeshPro"; const string ASMDEF_TMP = "Unity.TextMeshPro"; +#if !dUI_TextMeshPro [MenuItem("XCharts/TextMeshPro Enable")] +#endif public static void EnableTextMeshPro() { if (!IsSpecifyAssemblyExist(ASMDEF_TMP)) @@ -207,19 +209,39 @@ namespace XCharts.Editor Debug.LogError("TextMeshPro is not in the project, please import TextMeshPro package first."); return; } - DefineSymbolsUtil.AddGlobalDefine(SYMBOL_TMP); - XChartsMgr.RemoveAllChartObject(); - InsertSpecifyReferenceIntoAssembly(Platform.Editor, ASMDEF_TMP); - InsertSpecifyReferenceIntoAssembly(Platform.Runtime, ASMDEF_TMP); + if (EditorUtility.DisplayDialog("TextMeshPro Enable", "TextMeshPro is disabled, do you want to enable it?", "Yes", "Cancel")) + { + DefineSymbolsUtil.AddGlobalDefine(SYMBOL_TMP); + XChartsMgr.RemoveAllChartObject(); + CheckAsmdefTmpReference(true); + } } +#if dUI_TextMeshPro [MenuItem("XCharts/TextMeshPro Disable")] +#endif public static void DisableTextMeshPro() { - RemoveSpecifyReferenceFromAssembly(Platform.Editor, ASMDEF_TMP); - RemoveSpecifyReferenceFromAssembly(Platform.Runtime, ASMDEF_TMP); - DefineSymbolsUtil.RemoveGlobalDefine(SYMBOL_TMP); - XChartsMgr.RemoveAllChartObject(); + if (EditorUtility.DisplayDialog("TextMeshPro Disable", "TextMeshPro is enabled, do you want to disable it?", "Yes", "Cancel")) + { + CheckAsmdefTmpReference(false); + DefineSymbolsUtil.RemoveGlobalDefine(SYMBOL_TMP); + XChartsMgr.RemoveAllChartObject(); + } + } + + public static void CheckAsmdefTmpReference(bool enable) + { + if (enable) + { + InsertSpecifyReferenceIntoAssembly(Platform.Editor, ASMDEF_TMP); + InsertSpecifyReferenceIntoAssembly(Platform.Runtime, ASMDEF_TMP); + } + else + { + RemoveSpecifyReferenceFromAssembly(Platform.Editor, ASMDEF_TMP); + RemoveSpecifyReferenceFromAssembly(Platform.Runtime, ASMDEF_TMP); + } } #endif #endregion @@ -229,7 +251,10 @@ namespace XCharts.Editor //As InputSystem is released in 2019.1+ ,when unity version is 2019.1+ , enable InputSystem Support const string SYMBOL_I_S = "INPUT_SYSTEM_ENABLED"; const string ASMDEF_I_S = "Unity.InputSystem"; + +#if !INPUT_SYSTEM_ENABLED [MenuItem("XCharts/InputSystem Enable")] +#endif public static void EnableInputSystem() { if (!IsSpecifyAssemblyExist(ASMDEF_I_S)) @@ -237,20 +262,37 @@ namespace XCharts.Editor Debug.LogError("InputSystem is not in the project, please import InputSystem package first."); return; } - // insert input system package into editor and runtime assembly - InsertSpecifyReferenceIntoAssembly(Platform.Editor, ASMDEF_I_S); - InsertSpecifyReferenceIntoAssembly(Platform.Runtime, ASMDEF_I_S); - // add scripting define symbols - DefineSymbolsUtil.AddGlobalDefine(SYMBOL_I_S); + if (EditorUtility.DisplayDialog("InputSystem Enable", "InputSystem is disabled, do you want to enable it?", "Yes", "Cancel")) + { + CheckAsmdefInputSystemReference(true); + DefineSymbolsUtil.AddGlobalDefine(SYMBOL_I_S); + } } + +#if INPUT_SYSTEM_ENABLED [MenuItem("XCharts/InputSystem Disable")] +#endif public static void DisableInputSystem() { - // remove input system package into editor and runtime assembly - RemoveSpecifyReferenceFromAssembly(Platform.Editor, ASMDEF_I_S); - RemoveSpecifyReferenceFromAssembly(Platform.Runtime, ASMDEF_I_S); - // remove scripting define symbols - DefineSymbolsUtil.RemoveGlobalDefine(SYMBOL_I_S); + if (EditorUtility.DisplayDialog("InputSystem Disable", "InputSystem is enabled, do you want to disable it?", "Yes", "Cancel")) + { + CheckAsmdefInputSystemReference(false); + DefineSymbolsUtil.RemoveGlobalDefine(SYMBOL_I_S); + } + } + + public static void CheckAsmdefInputSystemReference(bool enable) + { + if(enable) + { + InsertSpecifyReferenceIntoAssembly(Platform.Editor, ASMDEF_I_S); + InsertSpecifyReferenceIntoAssembly(Platform.Runtime, ASMDEF_I_S); + } + else + { + RemoveSpecifyReferenceFromAssembly(Platform.Editor, ASMDEF_I_S); + RemoveSpecifyReferenceFromAssembly(Platform.Runtime, ASMDEF_I_S); + } } #endif #endregion diff --git a/Editor/XCharts.Editor.asmdef b/Editor/XCharts.Editor.asmdef index 4371b9b3..41ee37b6 100644 --- a/Editor/XCharts.Editor.asmdef +++ b/Editor/XCharts.Editor.asmdef @@ -1,7 +1,9 @@ { "name": "XCharts.Editor", "references": [ - "XCharts.Runtime" + "XCharts.Runtime", + "Unity.TextMeshPro", + "Unity.InputSystem" ], "includePlatforms": [ "Editor" diff --git a/Examples/Example01_RandomData.cs b/Examples/Example01_RandomData.cs index f869131a..5a8e5442 100644 --- a/Examples/Example01_RandomData.cs +++ b/Examples/Example01_RandomData.cs @@ -10,7 +10,7 @@ namespace XCharts.Example { [DisallowMultipleComponent] [RequireComponent(typeof(BaseChart))] - public class Example_RandomData : MonoBehaviour + public class Example01_RandomData : MonoBehaviour { public bool loopAdd = false; public float loopAddTime = 1f; diff --git a/Plugins/Editor.meta b/Plugins/Editor.meta new file mode 100644 index 00000000..30e454df --- /dev/null +++ b/Plugins/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 41bb9b8682a704809bf4e33c56813402 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index 789117d1..26f52adf 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -273,7 +273,7 @@ namespace XCharts.Runtime chartText = new ChartText(); #if dUI_TextMeshPro RemoveComponent(txtObj); - chartText.tmpText = GetOrAddComponent(txtObj); + chartText.tmpText = EnsureComponent(txtObj); chartText.tmpText.font = textStyle.tmpFont == null ? theme.tmpFont : textStyle.tmpFont; chartText.tmpText.fontStyle = textStyle.tmpFontStyle; chartText.tmpText.richText = true; diff --git a/Runtime/XCharts.Runtime.asmdef b/Runtime/XCharts.Runtime.asmdef index 64609360..629fc0b8 100644 --- a/Runtime/XCharts.Runtime.asmdef +++ b/Runtime/XCharts.Runtime.asmdef @@ -1,6 +1,9 @@ { "name": "XCharts.Runtime", - "references": [], + "references": [ + "Unity.TextMeshPro", + "Unity.InputSystem" + ], "includePlatforms": [], "excludePlatforms": [], "allowUnsafeCode": false,