/// <summary>
        /// 根据语言的枚举类型
        /// </summary>
        /// <param name="languageContainer"></param>
        private void GetLanguageConfigureOnLanguageType(ref List <ImageConfige> languageConfigContainer)
        {
            if (languageConfigContainer == null)
            {
                languageConfigContainer = new List <ImageConfige>();
            }
            var          allLanguage    = System.Enum.GetValues(typeof(LocalizationManager.LanguageType));
            ImageConfige firstConfigure = null;
            string       sptitePath     = ""; //根据不同的语言生成一个目录 自动关联

            foreach (var language in allLanguage)
            {
                ImageConfige config = null;
                LocalizationManager.LanguageType languageType = (LocalizationManager.LanguageType)System.Enum.Parse(typeof(LocalizationManager.LanguageType), language.ToString());
                if (languageConfigContainer.Count == 0)
                {
                    config = GetTargetImageProperty(languageType);
                    //     GetSpritePathByLanguage(ref sptitePath,config.m_SourceImage, LocalizationManager.GetLanguageName(config.m_Language));
                    firstConfigure = config;
                }
                else
                {
                    config = new ImageConfige(languageType, firstConfigure.m_ImageProperty);
                }
                if (IsExitLanguageConfigure(config.m_Language, m_TotalImageConfigure.m_ImageLanguageConfige))
                {
                    continue;
                }
                languageConfigContainer.Add(config);
            }
        }
 /// <summary>
 /// 重置
 /// </summary>
 public void Reset()
 {
     currentLanguageType = LocalizationManager.LanguageType.cn;
     m_lastLanguageType  = currentLanguageType;
     ResetConfig();
     SaveView(currentLanguageType);
 }
Beispiel #3
0
        /// <summary>
        /// 初始化视图
        /// </summary>
        private void InitView(LocalizationManager.LanguageType languageType)
        {
            TMPro.TextMeshProUGUI text = GetComponent <TMPro.TextMeshProUGUI>();
            text.text = LocalizationManager.GetInstance().GetLocalTextString("UIStatic/" + fileName, key, languageType);

            TextConfig textConfig = textConfigs.FirstOrDefault(x => x.languageType == languageType);

            if (textConfig == null)
            {
                return;
            }

            TextFontProperty fontProperty = textConfig.fontProperty;

            if (enableFontProperty)
            {
                text.font = fontProperty.font;
                text.fontSharedMaterial = fontProperty.fontSharedMaterial;
                text.fontStyle          = fontProperty.fontStyle;
                text.color              = fontProperty.color;
                text.colorGradient      = fontProperty.colorGradient;
                text.fontSize           = fontProperty.fontSize;
                text.alignment          = fontProperty.alignment;
                text.enableWordWrapping = fontProperty.enableWordWrapping;
                text.overflowMode       = fontProperty.overflowMode;
            }
        }
Beispiel #4
0
        /// <summary>
        /// 保存视图
        /// </summary>
        private void SaveView(LocalizationManager.LanguageType languageType)
        {
            TextConfig textConfig = textConfigs.FirstOrDefault(x => x.languageType == languageType);

            if (textConfig == null)
            {
                return;
            }

            TextFontProperty fontProperty = textConfig.fontProperty;

            if (enableFontProperty)
            {
                TMPro.TextMeshProUGUI text = GetComponent <TMPro.TextMeshProUGUI>();
                fontProperty.font = text.font;
                fontProperty.fontSharedMaterial = text.fontSharedMaterial;
                fontProperty.fontStyle          = text.fontStyle;
                fontProperty.color              = text.color;
                fontProperty.colorGradient      = text.colorGradient;
                fontProperty.fontSize           = text.fontSize;
                fontProperty.alignment          = text.alignment;
                fontProperty.enableWordWrapping = text.enableWordWrapping;
                fontProperty.overflowMode       = text.overflowMode;
            }
        }
Beispiel #5
0
 private void OnValidate()
 {
     if (m_lastLanguageType == currentLanguageType)
     {
         return;
     }
     InitView(currentLanguageType);
     m_lastLanguageType = currentLanguageType;
 }
        //获取第一个语言对应的配置 取当前脚本挂载对象上的属性
        private ImageConfige GetTargetImageProperty(LocalizationManager.LanguageType firstLanguage)
        {
            ImageConfige _configure = new ImageConfige();

            _configure.m_Language    = firstLanguage;
            _configure.m_SourceImage = m_TargetImage.sprite;
            InitialedImageProperty(ref _configure.m_ImageProperty);
            return(_configure);
        }
Beispiel #7
0
 private void OnValidate()
 {
     if (m_lastLanguageType == currentLanguageType)
     {
         return;
     }
     InitView(currentLanguageType);
     m_lastLanguageType = currentLanguageType;
     Debug.Log("切换语言完成!");
 }
Beispiel #8
0
        /// <summary>
        /// 初始化视图
        /// </summary>
        private void InitView(LocalizationManager.LanguageType languageType)
        {
            List <UITextLocalization> textLocalizations = new List <UITextLocalization>();

            gameObject.GetComponentsInChildren <UITextLocalization>(true, textLocalizations);
            foreach (UITextLocalization textLocalization in textLocalizations)
            {
                textLocalization.ChangeLanguageType(languageType);
            }
        }
 //检测当前语言是否已经配置过
 private bool IsExitLanguageConfigure(LocalizationManager.LanguageType language, List <ImageConfige> dataSource)
 {
     for (int dex = 0; dex < dataSource.Count; ++dex)
     {
         if (dataSource[dex].m_Language == language)
         {
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        /// 根据参数给定的语言切换图片
        /// </summary>
        /// <param name="language"></param>
        public void ShowImageViewBaseOnLanguage(LocalizationManager.LanguageType language)
        {
            ImageConfige newImageConfige = GetLanguageConfigure(language);

            if (newImageConfige == null)
            {
                Debug.LogError(string.Format("当前图片{0  }没有配置对应的语言{1}  ", gameObject.name, language));
                return;
            }
            InitialedImageProperty(newImageConfige);
        }
 //根据语言类型获取对应的配置
 private ImageConfige GetLanguageConfigure(LocalizationManager.LanguageType language)
 {
     for (int dex = 0; dex < m_TotalImageConfigure.m_ImageLanguageConfige.Count; ++dex)
     {
         if (m_TotalImageConfigure.m_ImageLanguageConfige[dex].m_Language == language)
         {
             return(m_TotalImageConfigure.m_ImageLanguageConfige[dex]);
         }
     }
     Debug.LogError("没有对应的语言配置" + language);
     return(null);
 }
        /// <summary>
        /// 重置配置
        /// </summary>
        protected override void ResetConfig()
        {
            base.ResetConfig();

            configs.Clear();
            foreach (var obj in System.Enum.GetValues(typeof(LocalizationManager.LanguageType)))
            {
                LocalizationManager.LanguageType languageType = (LocalizationManager.LanguageType)obj;
                Config config = new Config();
                config.languageName = languageType.ToString();
                config.languageType = languageType;
                configs.Add(config);
            }
        }
        /// <summary>
        /// 检测参数对应的语言配置是否可用(有语言配置相同)
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private bool IsLanguageConfigureEnable(List <ImageConfige> data, ref LocalizationManager.LanguageType repeatLanguage)
        {
            List <ImageConfige> readyCompareList = new List <ImageConfige>();  //已经匹配的不重复项

            for (int dex = 0; dex < data.Count; ++dex)
            {
                if (IsExitLanguageConfigure(data[dex].m_Language, readyCompareList))
                {
                    repeatLanguage = data[dex].m_Language;
                    return(false);
                }
                readyCompareList.Add(data[dex]);
            }
            return(true);
        }
Beispiel #14
0
        /// <summary>
        /// 重置
        /// </summary>
        public void Reset()
        {
            GenConfigKey();
            currentLanguageType = LocalizationManager.LanguageType.cn;
            m_lastLanguageType  = currentLanguageType;

            textConfigs.Clear();
            foreach (var obj in System.Enum.GetValues(typeof(LocalizationManager.LanguageType)))
            {
                LocalizationManager.LanguageType languageType = (LocalizationManager.LanguageType)obj;
                TextConfig textConfig = new TextConfig();
                textConfig.languageName = languageType.ToString();
                textConfig.languageType = languageType;
                textConfigs.Add(textConfig);
            }
        }
        ////当修改属性时候
        //private void OnValidate()
        //{
        //    OnEditorConfigure();
        //}
        #endregion

        /// <summary>
        /// 当编辑属性列表时候
        /// </summary>
        private void OnEditorConfigure()
        {
            if (m_TotalImageLanguageConfigure.Count == 0)
            {
                GetLanguageConfigureOnLanguageType(ref m_TotalImageLanguageConfigure);
            }

            LocalizationManager.LanguageType repeatLanguage = LocalizationManager.LanguageType.cn;
            if (IsLanguageConfigureEnable(m_TotalImageConfigure.m_ImageLanguageConfige, ref repeatLanguage))
            {
                m_TotalImageLanguageConfigure = m_TotalImageConfigure.m_ImageLanguageConfige;
            }
            else
            {
                Debug.LogError("当前更改的语言配置有问题 有重复的语言 " + repeatLanguage);
                m_TotalImageConfigure.m_ImageLanguageConfige = m_TotalImageLanguageConfigure; //保持修改前的属性不变
            }
        }
        /// <summary>
        /// 初始化视图
        /// </summary>
        protected override void InitView(LocalizationManager.LanguageType languageType)
        {
            Config config = configs.FirstOrDefault(x => x.languageType == languageType);

            if (config == null)
            {
                return;
            }
            if (!config.enable)
            {
                return;
            }

            TMPro.TextMeshProUGUI text = GetComponent <TMPro.TextMeshProUGUI>();
            if (text == null)
            {
                return;
            }
            config.property.CloneToTextMeshPro(text);
        }
        /// <summary>
        /// 初始化视图
        /// </summary>
        protected override void InitView(LocalizationManager.LanguageType languageType)
        {
            Config config = configs.FirstOrDefault(x => x.languageType == languageType);

            if (config == null)
            {
                return;
            }
            if (!config.enable)
            {
                return;
            }

            RectTransform rtf = transform as RectTransform;

            if (rtf == null)
            {
                return;
            }
            config.property.CloneToRectTransform(rtf);
        }
 public ImageConfige(LocalizationManager.LanguageType language, ImageProperty imageProperty)
 {
     m_Language      = language;
     m_LanguageName  = m_Language.ToString();
     m_ImageProperty = new ImageProperty(imageProperty);
 }
Beispiel #19
0
        private static void GenTextLocalizationByAppend(UnityEditor.MenuCommand cmd)
        {
            UITextLocalizationManager current = cmd.context as UITextLocalizationManager;

            if (current == null)
            {
                Debug.LogError("生成失败!");
                return;
            }

            GameObject goSelected = current.gameObject;
            List <TMPro.TextMeshProUGUI> textMeshes = new List <TMPro.TextMeshProUGUI>();

            goSelected.GetComponentsInChildren <TMPro.TextMeshProUGUI>(true, textMeshes);
            textMeshes = textMeshes.Where((textMesh) =>
            {
                if (textMesh.tag == "TMPro.TextMeshProUGUI" || textMesh.tag == "TextIngnoreLocalization")     //动态文本不处理
                {
                    return(false);
                }
                if (string.IsNullOrEmpty(textMesh.text))     //空文本不处理
                {
                    return(false);
                }
                float result;
                if (float.TryParse(textMesh.text, out result))     //数字不处理
                {
                    return(false);
                }
                return(true);
            }).ToList();

            if (textMeshes.Count == 0)
            {
                Debug.Log("没有Text组件需要本地化!");
                DestroyImmediate(current);
                return;
            }

            string fileName = goSelected.name;
            string filePath = EditorUtility.SaveFilePanel("生成Text组件本地化脚本", Application.dataPath + "/Resources/Localization/cn/UIStatic", fileName + ".txt", "txt");

            if (string.IsNullOrEmpty(filePath))
            {
                Debug.Log("已取消Text组件需要本地化!");
                return;
            }
            fileName = Path.GetFileNameWithoutExtension(filePath);

            foreach (var obj in System.Enum.GetValues(typeof(LocalizationManager.LanguageType)))
            {
                LocalizationManager.LanguageType languageType = (LocalizationManager.LanguageType)obj;
                string languageName = obj.ToString();

                filePath = string.Format("{0}/Resources/Localization/{1}/UIStatic/{2}.txt", Application.dataPath, languageName, fileName);
                JsonData jsonData = new JsonData();
                if (File.Exists(filePath))
                {
                    jsonData = JsonMapper.ToObject(Resources.Load <TextAsset>(string.Format("Localization/{0}/UIStatic/{1}", languageName, fileName)).text);
                }


                foreach (TMPro.TextMeshProUGUI textMesh in textMeshes)
                {
                    UITextLocalization textLocalization = textMesh.gameObject.GetComponent <UITextLocalization>();
                    if (textLocalization == null)
                    {
                        textLocalization = textMesh.gameObject.AddComponent <UITextLocalization>();
                    }
                    else
                    {
                        textLocalization.Reset();
                    }
                    textLocalization.fileName = fileName;

                    //if (isExitFile && jsonData.Contains(textLocalization.key))
                    //    continue;
                    if (jsonData.Contains(textLocalization.key))
                    {
                        continue;
                    }

                    string value = textMesh.text;
                    if (languageType != LocalizationManager.LanguageType.cn)
                    {
                        value += string.Format("({0})", languageName);
                    }
                    jsonData[textLocalization.key] = value;
                }

                StringBuilder sb = new StringBuilder();
                sb.Append("{\n");
                int dex = 0;
                foreach (string key in jsonData.Keys)
                {
                    if (dex == 0)
                    {
                        sb.Append(string.Format("\"{0}\":\"{1}\"\n", key, jsonData[key]));
                    }
                    else
                    {
                        sb.Append(string.Format("\"{0}\":\"{1}\",\n", key, jsonData[key]));
                    }
                }
                sb.Append("}");

                StreamWriter sw = new StreamWriter(filePath, false, Encoding.UTF8);
                sw.Write(sb.ToString());
                sw.Flush();
                sw.Close();
            }

            current.GetAllUITextLocalizations();
            AssetDatabase.Refresh();
            Debug.Log("生成Text组件本地化脚本完成!");
        }
Beispiel #20
0
 public void ChangeLanguageType(LocalizationManager.LanguageType languageType)
 {
     currentLanguageType = languageType;
     OnValidate();
 }
Beispiel #21
0
 /// <summary>
 /// 重置
 /// </summary>
 private void Reset()
 {
     currentLanguageType = LocalizationManager.LanguageType.cn;
     m_lastLanguageType  = currentLanguageType;
 }
 /// <summary>
 /// 切换语言
 /// </summary>
 /// <param name="languageType"></param>
 public void ChangeLanguageType(LocalizationManager.LanguageType languageType)
 {
     currentLanguageType = languageType;
     InitView(currentLanguageType);
 }
 /// <summary>
 /// 初始化视图
 /// </summary>
 protected virtual void InitView(LocalizationManager.LanguageType languageType)
 {
 }