少年修仙传客户端基础资源
0312 优化文字和字体替换,修复自动换行导致比较异常字号缩小问题
2个文件已修改
49 ■■■■ 已修改文件
Assets/Editor/Tool/ChangePrefabsFont.cs 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/Tool/ImportPrefabsWords.cs 40 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/Tool/ChangePrefabsFont.cs
@@ -55,10 +55,10 @@
        filepaths1.CopyTo(filepaths, 0);
        filepaths2.CopyTo(filepaths, filepaths1.Length);
        Debug.LogFormat("预修改预制体字体总数:{0}", filepaths.Length);
        int startIndex = 0;
        int startIndex = 0; //文件执行个数
        int a = 0;
        int i = 0;
        int a = 0;  // 总字体数
        int i = 0;  // 更换字体数
        EditorApplication.update = delegate () {
            string file = filepaths[startIndex];
            file = file.Substring(file.IndexOf("Assets"));
@@ -75,6 +75,7 @@
                if (item.font == fromChangeFont)
                {
                    item.font = toChangeFont;
                    item.fontSize = item.fontSize - 2;
                    EditorUtility.SetDirty(_prefab);
                    i++;
                }
@@ -83,12 +84,12 @@
            startIndex++;
            
            if (isCancel || startIndex >= filepaths.Length) {
                Debug.LogFormat("字体批量修改成功--检索{0}个预制体, 字体总个数{1},修改{2}", startIndex, a, i);
                EditorUtility.ClearProgressBar();
                EditorApplication.update = null;
                startIndex = 0;
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                Debug.LogFormat("字体批量修改成功--{0}", i);
            }
        };
    }
Assets/Editor/Tool/ImportPrefabsWords.cs
@@ -11,8 +11,6 @@
//!!!需要注意预制体导入的index要和导出的一致,避免遇到同名时无法区分的问题
public class ImportPrefabsWords : EditorWindow {
    private static string topFilePath=Application.dataPath + "/ResourcesOut/UI";
    [MenuItem("策划工具/==批量导入预制体文字==", false)]
    private static void Export()
@@ -29,30 +27,34 @@
        int startIndex = 0;
        int changeCnt = 0;
        EditorApplication.update = delegate () {
            if (startIndex >= lines.Length)
            {
                Debug.LogFormat("文字批量修改成功-- 检索{0}行,共替换{1}行", startIndex, changeCnt);
                EditorUtility.ClearProgressBar();
                EditorApplication.update = null;
                startIndex = 0;
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                return;
            }
            var lineStr = lines[startIndex];
            string[] info = lines[startIndex].Split('\t');
            startIndex++;
            if (info.Length != 4)
            {
                if (startIndex >= lines.Length) {
                    EditorUtility.ClearProgressBar();
                    EditorApplication.update = null;
                    startIndex = 0;
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                }
                Debug.LogFormat("异常:长度不对--执行到:第{0}行 {1}", startIndex, lineStr);
                return;
            }
            string file = info[0];
            int index = int.Parse(info[1]);
            string name = info[2];
            string content = info[3].Replace("\r\n","").Replace("\r","").Replace("\n","");
            string content = info[3].Replace("\r","").Replace("\n","");
            bool isCancel = EditorUtility.DisplayCancelableProgressBar("导入预制体文字-"+lines.Length, file, (float)startIndex / (float)lines.Length);
            GameObject _prefab = AssetDatabase.LoadAssetAtPath<GameObject>(file);
            if (_prefab == null)
            {
                if (isCancel || startIndex >= lines.Length) {
                if (isCancel) {
                    EditorUtility.ClearProgressBar();
                    EditorApplication.update = null;
@@ -60,6 +62,7 @@
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                }
                Debug.LogFormat("异常:预制体异常--执行到:第{0}行 {1}", startIndex, lineStr);
                return;
            }
            Text[] transArr = _prefab.GetComponentsInChildren<Text>(true);
@@ -67,10 +70,10 @@
            Text item = transArr[index];
            if (item.name == name)
            {
                if (item.text != content)
                var curText = item.text.Replace("\r", "").Replace("\n", "");
                if (curText != content)
                {
                    item.text = content;
                    item.fontSize = item.fontSize - 2;
                    EditorUtility.SetDirty(_prefab);
                    changeCnt++;
                    //Debug.LogFormat("字体批量文件--{0} , {1}", file, index);
@@ -78,18 +81,17 @@
            }
            else
            {
                Debug.LogErrorFormat("第{0}行替换失败{1},{2}", startIndex+1, file, name);
                Debug.LogErrorFormat("异常:第{0}行替换失败{1},{2}", startIndex, file, name);
            }
            if (isCancel || startIndex >= lines.Length) {
            if (isCancel || startIndex >= lines.Length)
            {
                Debug.LogFormat("文字批量修改成功-- 检索{0}行,共替换{1}行", startIndex, changeCnt);
                EditorUtility.ClearProgressBar();
                EditorApplication.update = null;
                startIndex = 0;
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                Debug.LogFormat("字体批量修改成功--{0}", changeCnt);
            }
        };