From b0959aaa0ffd1f5b92416d38c45aae5b12118c05 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期一, 25 一月 2021 16:11:44 +0800
Subject: [PATCH] 0312 优化文字和字体替换,修复自动换行导致比较异常字号缩小问题

---
 Assets/Editor/Tool/ImportPrefabsWords.cs |   40 +++++++++++++++++++++-------------------
 Assets/Editor/Tool/ChangePrefabsFont.cs  |    9 +++++----
 2 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/Assets/Editor/Tool/ChangePrefabsFont.cs b/Assets/Editor/Tool/ChangePrefabsFont.cs
index 1d46393..6d58dda 100644
--- a/Assets/Editor/Tool/ChangePrefabsFont.cs
+++ b/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);
             }
         };
     }
diff --git a/Assets/Editor/Tool/ImportPrefabsWords.cs b/Assets/Editor/Tool/ImportPrefabsWords.cs
index b0590b9..fb02fb4 100644
--- a/Assets/Editor/Tool/ImportPrefabsWords.cs
+++ b/Assets/Editor/Tool/ImportPrefabsWords.cs
@@ -11,8 +11,6 @@
 //锛侊紒锛侀渶瑕佹敞鎰忛鍒朵綋瀵煎叆鐨刬ndex瑕佸拰瀵煎嚭鐨勪竴鑷达紝閬垮厤閬囧埌鍚屽悕鏃舵棤娉曞尯鍒嗙殑闂
 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);
             }
         };
 

--
Gitblit v1.8.0