mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-14 20:00:09 +00:00
修复TextMeshPro关闭时残留组件影响Text初始化的问题
This commit is contained in:
@@ -79,6 +79,8 @@ slug: /changelog
|
||||
|
||||
## master
|
||||
|
||||
* (2025.01.08) 修复`TextMeshPro`关闭时残留组件影响`Text`初始化的问题
|
||||
|
||||
## v3.13.0
|
||||
|
||||
版本要点:
|
||||
|
||||
@@ -204,6 +204,25 @@ namespace XCharts.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveTMPComponents(GameObject gameObject)
|
||||
{
|
||||
var coms = gameObject.GetComponents<Component>();
|
||||
foreach (var com in coms)
|
||||
{
|
||||
if (com.GetType().FullName.Contains("TMPro"))
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
GameObject.DestroyImmediate(com as UnityEngine.Object);
|
||||
else
|
||||
GameObject.Destroy(com as UnityEngine.Object);
|
||||
#else
|
||||
GameObject.Destroy(com as UnityEngine.Object);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Obsolete("Use EnsureComponent instead")]
|
||||
public static T GetOrAddComponent<T>(Transform transform) where T : Component
|
||||
{
|
||||
@@ -239,7 +258,13 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (gameObject.GetComponent<T>() == null)
|
||||
{
|
||||
return gameObject.AddComponent<T>();
|
||||
var com = gameObject.AddComponent<T>();
|
||||
if (com == null)
|
||||
{
|
||||
RemoveTMPComponents(gameObject);
|
||||
return gameObject.AddComponent<T>();
|
||||
}
|
||||
return com;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user