From be3c8bf7cbef98b3ada4067954ad4286730c727f Mon Sep 17 00:00:00 2001
From: lcy <1459594991@qq.com>
Date: 星期六, 09 五月 2026 20:58:49 +0800
Subject: [PATCH] 592 多语言适配 提交主干
---
Main/Component/UI/Core/TextLanguageAdapter.cs | 41 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/Main/Component/UI/Core/TextLanguageAdapter.cs b/Main/Component/UI/Core/TextLanguageAdapter.cs
index 15f14aa..fea97e7 100644
--- a/Main/Component/UI/Core/TextLanguageAdapter.cs
+++ b/Main/Component/UI/Core/TextLanguageAdapter.cs
@@ -156,6 +156,8 @@
private bool m_IsApplied = false;
+ private void Awake() => DetectTargetComponent();
+
// 寮�鏀� set 鏉冮檺锛屽厑璁稿閮ㄦ垨缂栬緫鍣ㄦ墜鍔ㄨ祴鍊�
public TextComponentType TargetTextType
{
@@ -186,6 +188,32 @@
public bool HasConfig(string languageId) => m_LanguageConfigs.ContainsKey(languageId);
public List<string> GetConfiguredLanguages() => new List<string>(m_LanguageConfigs.keys);
+ private void DetectTargetComponent()
+ {
+ if (m_TargetTextComponent != null)
+ {
+ DetermineTextType(m_TargetTextComponent);
+ return;
+ }
+
+ m_TargetTextComponent = GetComponent<TextEx>() ?? GetComponentInChildren<TextEx>(true) as Component
+ ?? GetComponent<GradientText>() ?? GetComponentInChildren<GradientText>(true) as Component
+ ?? GetComponent<Text>() ?? GetComponentInChildren<Text>(true) as Component;
+
+ DetermineTextType(m_TargetTextComponent);
+ }
+
+ private void DetermineTextType(Component component)
+ {
+ m_TargetTextType = component switch
+ {
+ TextEx _ => TextComponentType.TextEx,
+ GradientText _ => TextComponentType.GradientText,
+ Text _ => TextComponentType.Text,
+ _ => TextComponentType.None
+ };
+ }
+
public void ApplyConfig(string languageId)
{
var config = GetConfig(languageId);
@@ -214,6 +242,19 @@
}
#if UNITY_EDITOR
+ private void Reset()
+ {
+ DetectTargetComponent();
+ if (!HasConfig(DefaultLangId)) ReadCurrentToConfig(DefaultLangId);
+ }
+
+ [ContextMenu("鍒锋柊缁勪欢妫�娴�")]
+ public void Editor_ForceRefreshDetection()
+ {
+ DetectTargetComponent();
+ UnityEditor.EditorUtility.SetDirty(this);
+ }
+
[ContextMenu("璇诲彇褰撳墠閰嶇疆")]
public void Editor_ReadCurrentConfig()
{
--
Gitblit v1.8.0