lcy
2 天以前 be3c8bf7cbef98b3ada4067954ad4286730c727f
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()
    {