修复XCharts本地开启TextMeshProNewInputSystem后更新版本会报错的问题 (#272)

This commit is contained in:
monitor1394
2023-08-14 21:57:17 +08:00
parent 71c8bc1499
commit 0c187b6ff9
9 changed files with 109 additions and 32 deletions

View File

@@ -69,13 +69,16 @@ slug: /changelog
版本要点: 版本要点:
* 重构和完善动画系统,增加`新增动画``交互动画`的支持 * 重构`Animation`动画系统,增加`新增动画``交互动画`的支持
* 完善`PieChart`的动画交互表现 * 完善`PieChart`的动画交互表现
* 增加`Symbol``EmptyTriangle``EmptyDiamond``Plus``Minus`四种新标记 * 增加`Symbol``EmptyTriangle``EmptyDiamond``Plus``Minus`四种新标记
* 完善图表的交互回调 * 完善`Chart`的鼠标交互回调
* 增加`LabelLine`可固定横坐标的功能
* 修复千年老问题开启TMP后更新版本会报错的问题
日志详情: 日志详情:
* (2023.08.14) 修复`XCharts`本地开启`TextMeshPro``NewInputSystem`后更新版本会报错的问题 (#272)
* (2023.08.12) 修复`Chart`在运行时被删除时会异常报错的问题 (#269) * (2023.08.12) 修复`Chart`在运行时被删除时会异常报错的问题 (#269)
* (2023.08.11) 修复`DataZoom`开启时可能会导致无法添加数据的问题 * (2023.08.11) 修复`DataZoom`开启时可能会导致无法添加数据的问题
* (2023.08.11) 修复`SerieData`单独设置`ItemStyle``itemFormatter`不生效的问题 * (2023.08.11) 修复`SerieData`单独设置`ItemStyle``itemFormatter`不生效的问题

View File

@@ -5,9 +5,9 @@ using XCharts.Runtime;
namespace XCharts.Editor 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, static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets,
string[] movedFromAssetsPaths) string[] movedFromAssetsPaths)
@@ -28,16 +28,35 @@ namespace XCharts.Editor
var fileName = Path.GetFileName(assetPath); var fileName = Path.GetFileName(assetPath);
if (fileName.Equals("XCSettings.asset")) if (fileName.Equals("XCSettings.asset"))
{ {
CheckAsmdef();
XCThemeMgr.ReloadThemeList(); XCThemeMgr.ReloadThemeList();
return;
} }
if (!IsThemeAsset(assetPath)) return; else if (IsThemeAsset(assetPath))
{
var theme = AssetDatabase.LoadAssetAtPath<Theme>(assetPath); var theme = AssetDatabase.LoadAssetAtPath<Theme>(assetPath);
if (XCSettings.AddCustomTheme(theme)) if (XCSettings.AddCustomTheme(theme))
{ {
XCThemeMgr.ReloadThemeList(); 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) public static void CheckDeletedAsset(string assetPath)
{ {

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 4b4ba2a9503ae46b1b7b1ae94ec59127 guid: 036a714dab7744d76849114f5bcf59a9
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -199,7 +199,9 @@ namespace XCharts.Editor
const string SYMBOL_TMP = "dUI_TextMeshPro"; const string SYMBOL_TMP = "dUI_TextMeshPro";
const string ASMDEF_TMP = "Unity.TextMeshPro"; const string ASMDEF_TMP = "Unity.TextMeshPro";
#if !dUI_TextMeshPro
[MenuItem("XCharts/TextMeshPro Enable")] [MenuItem("XCharts/TextMeshPro Enable")]
#endif
public static void EnableTextMeshPro() public static void EnableTextMeshPro()
{ {
if (!IsSpecifyAssemblyExist(ASMDEF_TMP)) if (!IsSpecifyAssemblyExist(ASMDEF_TMP))
@@ -207,19 +209,39 @@ namespace XCharts.Editor
Debug.LogError("TextMeshPro is not in the project, please import TextMeshPro package first."); Debug.LogError("TextMeshPro is not in the project, please import TextMeshPro package first.");
return; return;
} }
if (EditorUtility.DisplayDialog("TextMeshPro Enable", "TextMeshPro is disabled, do you want to enable it?", "Yes", "Cancel"))
{
DefineSymbolsUtil.AddGlobalDefine(SYMBOL_TMP); DefineSymbolsUtil.AddGlobalDefine(SYMBOL_TMP);
XChartsMgr.RemoveAllChartObject(); XChartsMgr.RemoveAllChartObject();
CheckAsmdefTmpReference(true);
}
}
#if dUI_TextMeshPro
[MenuItem("XCharts/TextMeshPro Disable")]
#endif
public static void DisableTextMeshPro()
{
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.Editor, ASMDEF_TMP);
InsertSpecifyReferenceIntoAssembly(Platform.Runtime, ASMDEF_TMP); InsertSpecifyReferenceIntoAssembly(Platform.Runtime, ASMDEF_TMP);
} }
else
[MenuItem("XCharts/TextMeshPro Disable")]
public static void DisableTextMeshPro()
{ {
RemoveSpecifyReferenceFromAssembly(Platform.Editor, ASMDEF_TMP); RemoveSpecifyReferenceFromAssembly(Platform.Editor, ASMDEF_TMP);
RemoveSpecifyReferenceFromAssembly(Platform.Runtime, ASMDEF_TMP); RemoveSpecifyReferenceFromAssembly(Platform.Runtime, ASMDEF_TMP);
DefineSymbolsUtil.RemoveGlobalDefine(SYMBOL_TMP); }
XChartsMgr.RemoveAllChartObject();
} }
#endif #endif
#endregion #endregion
@@ -229,7 +251,10 @@ namespace XCharts.Editor
//As InputSystem is released in 2019.1+ ,when unity version is 2019.1+ , enable InputSystem Support //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 SYMBOL_I_S = "INPUT_SYSTEM_ENABLED";
const string ASMDEF_I_S = "Unity.InputSystem"; const string ASMDEF_I_S = "Unity.InputSystem";
#if !INPUT_SYSTEM_ENABLED
[MenuItem("XCharts/InputSystem Enable")] [MenuItem("XCharts/InputSystem Enable")]
#endif
public static void EnableInputSystem() public static void EnableInputSystem()
{ {
if (!IsSpecifyAssemblyExist(ASMDEF_I_S)) 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."); Debug.LogError("InputSystem is not in the project, please import InputSystem package first.");
return; return;
} }
// insert input system package into editor and runtime assembly if (EditorUtility.DisplayDialog("InputSystem Enable", "InputSystem is disabled, do you want to enable it?", "Yes", "Cancel"))
InsertSpecifyReferenceIntoAssembly(Platform.Editor, ASMDEF_I_S); {
InsertSpecifyReferenceIntoAssembly(Platform.Runtime, ASMDEF_I_S); CheckAsmdefInputSystemReference(true);
// add scripting define symbols
DefineSymbolsUtil.AddGlobalDefine(SYMBOL_I_S); DefineSymbolsUtil.AddGlobalDefine(SYMBOL_I_S);
} }
}
#if INPUT_SYSTEM_ENABLED
[MenuItem("XCharts/InputSystem Disable")] [MenuItem("XCharts/InputSystem Disable")]
#endif
public static void DisableInputSystem() public static void DisableInputSystem()
{ {
// remove input system package into editor and runtime assembly 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.Editor, ASMDEF_I_S);
RemoveSpecifyReferenceFromAssembly(Platform.Runtime, ASMDEF_I_S); RemoveSpecifyReferenceFromAssembly(Platform.Runtime, ASMDEF_I_S);
// remove scripting define symbols }
DefineSymbolsUtil.RemoveGlobalDefine(SYMBOL_I_S);
} }
#endif #endif
#endregion #endregion

View File

@@ -1,7 +1,9 @@
{ {
"name": "XCharts.Editor", "name": "XCharts.Editor",
"references": [ "references": [
"XCharts.Runtime" "XCharts.Runtime",
"Unity.TextMeshPro",
"Unity.InputSystem"
], ],
"includePlatforms": [ "includePlatforms": [
"Editor" "Editor"

View File

@@ -10,7 +10,7 @@ namespace XCharts.Example
{ {
[DisallowMultipleComponent] [DisallowMultipleComponent]
[RequireComponent(typeof(BaseChart))] [RequireComponent(typeof(BaseChart))]
public class Example_RandomData : MonoBehaviour public class Example01_RandomData : MonoBehaviour
{ {
public bool loopAdd = false; public bool loopAdd = false;
public float loopAddTime = 1f; public float loopAddTime = 1f;

8
Plugins/Editor.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 41bb9b8682a704809bf4e33c56813402
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -273,7 +273,7 @@ namespace XCharts.Runtime
chartText = new ChartText(); chartText = new ChartText();
#if dUI_TextMeshPro #if dUI_TextMeshPro
RemoveComponent<Text>(txtObj); RemoveComponent<Text>(txtObj);
chartText.tmpText = GetOrAddComponent<TextMeshProUGUI>(txtObj); chartText.tmpText = EnsureComponent<TextMeshProUGUI>(txtObj);
chartText.tmpText.font = textStyle.tmpFont == null ? theme.tmpFont : textStyle.tmpFont; chartText.tmpText.font = textStyle.tmpFont == null ? theme.tmpFont : textStyle.tmpFont;
chartText.tmpText.fontStyle = textStyle.tmpFontStyle; chartText.tmpText.fontStyle = textStyle.tmpFontStyle;
chartText.tmpText.richText = true; chartText.tmpText.richText = true;

View File

@@ -1,6 +1,9 @@
{ {
"name": "XCharts.Runtime", "name": "XCharts.Runtime",
"references": [], "references": [
"Unity.TextMeshPro",
"Unity.InputSystem"
],
"includePlatforms": [], "includePlatforms": [],
"excludePlatforms": [], "excludePlatforms": [],
"allowUnsafeCode": false, "allowUnsafeCode": false,