using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using System.IO; using UnityEngine.UI; using vnxbqy.UI; using System.Reflection; // 导出文本规格,如长宽,字体,字号,颜色,描边,阴影,行间距 public class ExportPrefabsWordFormat : EditorWindow { private static string topFilePath=Application.dataPath + "/ResourcesOut/UI"; [MenuItem("策划工具/批量导出预制体文本格式", false)] private static void Export() { string writePath = "exportFontSize.txt"; if (File.Exists(writePath)) { File.Delete(writePath); } FileStream fs = new FileStream(writePath,FileMode.Create);//如不存在,则创建新的文本文档 string writeline1 = string.Format("路径\t索引\t名字\t宽\t高\tanchorMinX\tanchorMinY\tanchorMaxX\tanchorMaxY\tanchoredPositionX\tanchoredPositionY\tpivotX\tpivotY\tlocalScaleX\tlocalScaleY\t字大小\t对齐\t行宽\t横溢出\t竖溢出\t自适应\t自适应最小\t自适应最大\r\n"); byte[] data1 = System.Text.Encoding.UTF8.GetBytes(writeline1); fs.Write(data1, 0, data1.Length); topFilePath = Application.dataPath + "/ResourcesOut/UI"; string[] filepaths1 = Directory.GetFiles(topFilePath, "*.prefab", SearchOption.AllDirectories); Debug.LogFormat("批量导出UI预制体文本格式路径{0}, {1}", topFilePath, filepaths1.Length); topFilePath = Application.dataPath + "/ResourcesOut/BuiltIn"; string[] filepaths2 = Directory.GetFiles(topFilePath, "*.prefab", SearchOption.AllDirectories); Debug.LogFormat("批量导出BuiltIn预制体文本格式路径{0}, {1}", topFilePath, filepaths2.Length); 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 b = 0; int c = 0; int d = 0; int e = 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(file); Text[] transArr14 = _prefab.GetComponentsInChildren(true); a += transArr14.Length; RichText[] transArr11 = _prefab.GetComponentsInChildren(true); b += transArr11.Length; TextImage[] transArr12 = _prefab.GetComponentsInChildren(true); c += transArr12.Length; OffsetImage2[] transArr13 = _prefab.GetComponentsInChildren(true); d += transArr13.Length; TextEx[] transArr = _prefab.GetComponentsInChildren(true); e += transArr.Length; //Debug.LogFormat("{0}包含TextEx个数 {1}", file, transArr.Length); int i = 0; foreach (Text item in transArr14) { var test1 = item as TextImage; if (test1 != null) { i++; continue; } var test2 = item as OffsetImage2; if (test2 != null) { i++; continue; } RectTransform rectTransform = item.GetComponent(); string writeline = string.Format($"{file}\t{i}\t{item.name}\t{rectTransform.sizeDelta.x}\t{rectTransform.sizeDelta.y}\t{rectTransform.anchorMin.x}\t{rectTransform.anchorMin.y}\t{rectTransform.anchorMax.x}\t{rectTransform.anchorMax.y}\t{rectTransform.anchoredPosition.x}\t{rectTransform.anchoredPosition.y}\t{rectTransform.pivot.x}\t{rectTransform.pivot.y}\t{rectTransform.localScale.x}\t{rectTransform.localScale.y}\t{item.fontSize}\t{item.alignment}\t{item.lineSpacing}\t{item.horizontalOverflow}\t{item.verticalOverflow}\t{item.resizeTextForBestFit}\t{item.resizeTextMinSize}\t{item.resizeTextMaxSize}\r\n"); byte[] data = System.Text.Encoding.UTF8.GetBytes(writeline); fs.Write(data, 0, data.Length); i++; } startIndex++; if (isCancel || startIndex >= filepaths.Length) { Debug.LogFormat("Text:{0},RichText:{1},TextImage:{2},OffsetImage2:{3},TextEx:{4}", a,b,c,d,e); EditorUtility.ClearProgressBar(); EditorApplication.update = null; startIndex = 0; fs.Flush(); fs.Close();//关闭 } }; } }