Unity 多语言 轻量高效的多语言工具集 LanguageManager
效果展示
支持excel导入自动化
组件化 更方便
也提供直接获取多语言的接口
没有挂 LanguageText的对象也可以获取多语言文本内容
支持 Format接口 可以传递N个参数进来组装多语言
支持首次系统语言自测
支持语言切换后本地自动保存配置
支持实时切换 同步刷新所有UI
容错处理
- 当设置当前多语言为 不存在的多语言语种 时 选择默认语言( 英文 )
- 当默认语言( 英文 ) 没有的时候 默认选择第一个多语言
- 当更新多语言时 新的多语言只有存在的时候才会刷新文本显示 避免多语言ID错误
- 每个LanguageText组件 提供 UpdateText( string customContent = null ) 可以自定义设置文本
部分源码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;[RequireComponent( typeof( Text ) )]
public class LanguageText : MonoBehaviour
{[SerializeField]private int m_mulID = 0;//多语言IDpublic int mulID{get{return m_mulID;}set{ var newTextValue = LanguageManager.GetInstance().GetText( value );if ( !string.IsNullOrEmpty( newTextValue ) ){m_mulID = value;UpdateText( newTextValue );}}}//UGUI Text 句柄Text textHandler = null;//可以指定内容public void UpdateText( string customContent = null ){if ( null == textHandler ){textHandler = GetComponent<Text>();}if( customContent == null ){customContent = LanguageManager.GetInstance().GetText( mulID );}textHandler.text = customContent;}private void Awake(){LanguageManager.GetInstance().___AddLanguageTextComponent( this );}private void OnEnable(){if ( !LanguageManager.GetInstance().inite ){//未初始完成 后续初始化完成后会由Manager再调用更新的 不用担心return;}UpdateText();}//有可能切出去修改了设备语言private void OnApplicationFocus( bool focus ){if ( focus ) UpdateText();}private void OnDestroy(){LanguageManager.GetInstance().___RemoveLanguageTextComponent( this );}
}