From 32b6374d997af0e6a63b83d5e823dbcd0bc9d0ac Mon Sep 17 00:00:00 2001 From: hch <305670599@qq.com> Date: 星期三, 17 九月 2025 17:19:02 +0800 Subject: [PATCH] 0312 检测字体工具 --- Assets/Editor/Tool/ChangePrefabsFontSize.cs | 73 +++++++++++++++++++++++++++++++++--- 1 files changed, 67 insertions(+), 6 deletions(-) diff --git a/Assets/Editor/Tool/ChangePrefabsFontSize.cs b/Assets/Editor/Tool/ChangePrefabsFontSize.cs index 035b020..1412f46 100644 --- a/Assets/Editor/Tool/ChangePrefabsFontSize.cs +++ b/Assets/Editor/Tool/ChangePrefabsFontSize.cs @@ -23,12 +23,71 @@ { Change(); } + if (GUILayout.Button("妫�娴嬪瓧浣撳拰rect鐨勯珮搴�")) + { + FindSmallRect(); + } + } + + + public static void FindSmallRect() + { + string topFilePath = Application.dataPath + "/ResourcesOut/UI"; + + + string[] filepaths1 = Directory.GetFiles(topFilePath, "*.prefab", SearchOption.AllDirectories); + topFilePath = Application.dataPath + "/ResourcesOut/BuiltIn"; + string[] filepaths2 = Directory.GetFiles(topFilePath, "*.prefab", SearchOption.AllDirectories); + topFilePath = Application.dataPath + "/ResourcesOut/UIComp"; + string[] filepaths3 = Directory.GetFiles(topFilePath, "*.prefab", SearchOption.AllDirectories); + + string[] filepaths = new string[filepaths1.Length + filepaths2.Length + filepaths3.Length]; + + filepaths1.CopyTo(filepaths, 0); + filepaths2.CopyTo(filepaths, filepaths1.Length); + filepaths3.CopyTo(filepaths, filepaths1.Length + filepaths2.Length); + Debug.LogFormat("棰勪慨鏀归鍒朵綋瀛椾綋鎬绘暟锛歿0}", filepaths.Length); + int startIndex = 0; //鏂囦欢鎵ц涓暟 + + int a = 0; // 鎬诲瓧浣撴暟 + EditorApplication.update = delegate () + { + string file = filepaths[startIndex]; + file = file.Substring(file.IndexOf("Assets")); + bool isCancel = EditorUtility.DisplayCancelableProgressBar("棰勫埗浣撴枃瀛�-" + filepaths.Length, file, (float)startIndex / (float)filepaths.Length); + GameObject _prefab = AssetDatabase.LoadAssetAtPath<GameObject>(file); + + Text[] transArr14 = _prefab.GetComponentsInChildren<Text>(true); + a += transArr14.Length; + + foreach (Text item in transArr14) + { + if (item.rectTransform.sizeDelta.y - item.fontSize <= 3) + { + Debug.LogFormat("鐣岄潰 {0} 瀛椾綋妫�娴嬪お灏� {1}锛� {2}", file, item.rectTransform.sizeDelta.y, item.fontSize); + } + + } + + + startIndex++; + + if (isCancel || startIndex >= filepaths.Length) + { + Debug.LogFormat("妫�娴嬪瓧浣撳拰rect鐨勯珮搴�--妫�绱0}涓鍒朵綋, 瀛椾綋鎬讳釜鏁皗1}", startIndex, a); + EditorUtility.ClearProgressBar(); + EditorApplication.update = null; + startIndex = 0; + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + } + }; } public static void Change() { - string topFilePath=Application.dataPath + "/ResourcesOut/UI"; + string topFilePath = Application.dataPath + "/ResourcesOut/UI"; string[] filepaths1 = Directory.GetFiles(topFilePath, "*.prefab", SearchOption.AllDirectories); @@ -47,10 +106,11 @@ int a = 0; // 鎬诲瓧浣撴暟 int i = 0; // 鏇存崲瀛椾綋鏁� - EditorApplication.update = delegate () { + EditorApplication.update = delegate () + { string file = filepaths[startIndex]; file = file.Substring(file.IndexOf("Assets")); - bool isCancel = EditorUtility.DisplayCancelableProgressBar("棰勫埗浣撴枃瀛�-"+filepaths.Length, file, (float)startIndex / (float)filepaths.Length); + bool isCancel = EditorUtility.DisplayCancelableProgressBar("棰勫埗浣撴枃瀛�-" + filepaths.Length, file, (float)startIndex / (float)filepaths.Length); GameObject _prefab = AssetDatabase.LoadAssetAtPath<GameObject>(file); Text[] transArr14 = _prefab.GetComponentsInChildren<Text>(true); @@ -67,15 +127,16 @@ } if (change) - { + { EditorUtility.SetDirty(_prefab); Debug.LogFormat("鐣岄潰 {0} 瀛椾綋澶у皬淇敼鎴愬姛", file); i++; } startIndex++; - - if (isCancel || startIndex >= filepaths.Length) { + + if (isCancel || startIndex >= filepaths.Length) + { Debug.LogFormat("瀛椾綋鎵归噺淇敼鎴愬姛--妫�绱0}涓鍒朵綋, 瀛椾綋鎬讳釜鏁皗1}锛屼慨鏀箋2}", startIndex, a, i); EditorUtility.ClearProgressBar(); EditorApplication.update = null; -- Gitblit v1.8.0