| | |
| | | |
| | | private bool m_IsApplied = false; |
| | | |
| | | private void Awake() => DetectTargetComponent(); |
| | | |
| | | // 开放 set 权限,允许外部或编辑器手动赋值 |
| | | public TextComponentType TargetTextType |
| | | { |
| | |
| | | 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); |
| | |
| | | } |
| | | |
| | | #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() |
| | | { |