From 47f7782cb80d3ae5e776b9188f160bd7a17943c4 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期五, 19 一月 2024 16:43:54 +0800
Subject: [PATCH] 0312 调整字体大小
---
Assets/Editor/Tool/ChangePrefabsFontSize.cs | 113 +++++++++++++++++++++++++++++++++++++
Assets/Editor/Tool/ChangePrefabsFontSize.cs.meta | 11 +++
2 files changed, 124 insertions(+), 0 deletions(-)
diff --git a/Assets/Editor/Tool/ChangePrefabsFontSize.cs b/Assets/Editor/Tool/ChangePrefabsFontSize.cs
new file mode 100644
index 0000000..cab4c36
--- /dev/null
+++ b/Assets/Editor/Tool/ChangePrefabsFontSize.cs
@@ -0,0 +1,113 @@
+锘縰sing System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEditor;
+using System.IO;
+using UnityEngine.UI;
+using Snxxz.UI;
+
+//鏍规嵁椤圭洰褰撲笅鎯呭喌璋冩暣锛岃皑鎱庝娇鐢�
+public class ChangePrefabsFontSize : EditorWindow {
+
+
+ [MenuItem("绛栧垝宸ュ叿/鏇存敼瀛椾綋澶у皬锛堟厧鐢級")]
+ public static void Open()
+ {
+ EditorWindow.GetWindow(typeof(ChangePrefabsFontSize));
+ }
+
+
+ Font fromFont;
+ static Font fromChangeFont;
+ void OnGUI()
+ {
+ GUILayout.Label("瀛椾綋");
+ fromFont = (Font)EditorGUILayout.ObjectField(fromFont, typeof(Font), true, GUILayout.MinWidth(100f));
+ fromChangeFont = fromFont;
+ if (GUILayout.Button("鏇存崲瀛椾綋澶у皬"))
+ {
+ Change();
+ }
+ }
+
+ public static void Change()
+ {
+
+ 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);
+
+
+ string[] filepaths = new string[filepaths1.Length + filepaths2.Length];
+
+ filepaths1.CopyTo(filepaths, 0);
+ filepaths2.CopyTo(filepaths, filepaths1.Length);
+ Debug.LogFormat("棰勪慨鏀归鍒朵綋瀛椾綋鎬绘暟锛歿0}", filepaths.Length);
+ int startIndex = 0; //鏂囦欢鎵ц涓暟
+
+ int a = 0; // 鎬诲瓧浣撴暟
+ int i = 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.font == fromChangeFont)
+ {
+ bool change = true;
+ if (item.rectTransform.rect.height <= 2)
+ {
+ change = false;
+ }
+ //else if (item.resizeTextForBestFit && item.resizeTextMaxSize > 24)
+ //{
+ // item.fontSize = 24;
+ // item.resizeTextMaxSize = 24;
+ //}
+ //else if (item.fontSize > 16 && item.fontSize <= 24)
+ //{
+ // item.fontSize = item.fontSize - 1;
+ //}
+ else if (item.fontSize > 24)
+ {
+ item.fontSize = 24;
+ }
+ else
+ {
+ change = false;
+ }
+ if (change)
+ {
+ EditorUtility.SetDirty(_prefab);
+ Debug.LogFormat("鐣岄潰 {0} 瀛椾綋澶у皬淇敼鎴愬姛", file);
+ i++;
+ }
+ }
+
+ }
+
+ 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();
+ }
+ };
+ }
+
+
+
+}
diff --git a/Assets/Editor/Tool/ChangePrefabsFontSize.cs.meta b/Assets/Editor/Tool/ChangePrefabsFontSize.cs.meta
new file mode 100644
index 0000000..d3852e9
--- /dev/null
+++ b/Assets/Editor/Tool/ChangePrefabsFontSize.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 9fab55616476536488b838e6247bf7ea
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
--
Gitblit v1.8.0