zoukankan      html  css  js  c++  java
  • 查找界面预设中的中文

      需求如上一篇。

      预设中很多UILabel,是在编辑器阶段直接赋值,因此需要逐个替换,可以将简体和繁体替换的文字做成字典,简体为key,繁体为value。

      对UIlabel中的text进行逐行替换。

      需要注意换行符

      上代码

     [MenuItem("Assets/misc/批量替换text中的中文")]
        static void 批量替换text中的中文()
        {
            Dictionary<string, string> replaceDic = new Dictionary<string, string>();//替换列表,示例
            replaceDic.Add("简体第一行", "繁体第一行");
            replaceDic.Add("简体第二行", "繁体第二行");
    
    
            EditorUtility.DisplayProgressBar("处理中 请稍等", "请勿操作", 0);
            StringBuilder info = new StringBuilder();
            var gameObjects = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
            for (int i = 0; i < gameObjects.Length; i++)
            {
    
                EditorUtility.DisplayProgressBar("处理中 请稍等", "正在处理:" + gameObjects[i].name, (i + 1f) / gameObjects.Length);
                string path = AssetDatabase.GetAssetPath(gameObjects[i]);
                if (!path.Contains(".prefab"))
                {
                    continue;
                }
                GameObject go = PrefabUtility.InstantiatePrefab(gameObjects[i]) as GameObject;
                UILabel[] uiLabel = go.GetComponentsInChildren<UILabel>(true);
                //获取物体路径
                if (uiLabel.Length > 0)
                {
                    for (int j = 0; j < uiLabel.Length; j++)
                    {
                        string[] str = uiLabel[j].text.Split("
    ".ToCharArray());
                        for (int k = 0; k < str.Length; k++)
                        {
                            if (replaceDic.ContainsKey(str[k]))
                            {
                                string key = str[k];
                                str[k] = replaceDic[key];
                            }
                        }
                        string allStr = "";
                        for (int k = 0; k < str.Length; k++)
                        {
                            allStr += str[k];
                            if (k != str.Length - 1)
                            {
                                allStr += "
    ";
                            }
                        }
                        uiLabel[j].text = allStr;
                    }
                }
                PrefabUtility.ReplacePrefab(go, gameObjects[i]);//替换
                Object.DestroyImmediate(go);
            }
            AssetDatabase.SaveAssets();//保存
            AssetDatabase.Refresh();
            EditorUtility.ClearProgressBar();
        }
  • 相关阅读:
    setTimeout中0毫秒延时
    javascript中call和apply方法
    javascript闭包
    apns 服务
    新的开始,新的起点
    心情笔记
    如何解决控件附件上传时超大附件无法上传的问题
    BPM实例分享——日期自动计算
    BPM实例分享——金额规则大写
    分享一个程序猿在流程数据查看权限问题的总结
  • 原文地址:https://www.cnblogs.com/lihangppz/p/7992142.html
Copyright © 2011-2022 走看看