| using System.Collections; | 
| using System.Collections.Generic; | 
| using UnityEngine; | 
| using UnityEditor; | 
| using System.IO; | 
| using UnityEngine.UI; | 
| using Snxxz.UI; | 
|   | 
|   | 
| public class ExportPrefabsWords : EditorWindow { | 
|   | 
|     private static string topFilePath=Application.dataPath + "/ResourcesOut/UI"; | 
|   | 
|   | 
|     [MenuItem("策划工具/批量导出预制体文字", false)] | 
|     private static void Export() | 
|     { | 
|   | 
|         string writePath = "export.txt"; | 
|         if (File.Exists(writePath)) | 
|         { | 
|             File.Delete(writePath); | 
|         } | 
|         FileStream fs = new FileStream(writePath,FileMode.Create);//如不存在,则创建新的文本文档 | 
|   | 
|   | 
|         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<GameObject>(file); | 
|   | 
|             Text[] transArr14 = _prefab.GetComponentsInChildren<Text>(true); | 
|             a += transArr14.Length; | 
|             RichText[] transArr11 = _prefab.GetComponentsInChildren<RichText>(true); | 
|             b += transArr11.Length; | 
|             TextImage[] transArr12 = _prefab.GetComponentsInChildren<TextImage>(true); | 
|             c += transArr12.Length; | 
|             OffsetImage2[] transArr13 = _prefab.GetComponentsInChildren<OffsetImage2>(true); | 
|             d += transArr13.Length; | 
|             TextEx[] transArr = _prefab.GetComponentsInChildren<TextEx>(true); | 
|             e += transArr.Length; | 
|             //Debug.LogFormat("{0}包含TextEx个数 {1}", file, transArr.Length); | 
|             int i = 0; | 
|             foreach (Text item in transArr14) | 
|             { | 
|                 TextEx tmpTextEx = item as TextEx; | 
|                 RichText tmpRichText = item as RichText; | 
|                 bool isNeedTrans = true; | 
|                 if ((tmpTextEx != null && tmpTextEx.isKey) || (tmpRichText != null && tmpRichText.language))  | 
|                 { | 
|                     isNeedTrans = false; | 
|                 } | 
|                 // /Debug.LogFormat("{0}包含文字 {1}-{2}", file, item.name, item.text); | 
|                 string temp = item.text.Replace("\r\n","").Replace("\r","").Replace("\n",""); | 
|                 string writeline = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\r\n", file, i, item.name, temp, isNeedTrans); | 
|                 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();//关闭 | 
|   | 
|   | 
|             } | 
|         }; | 
|   | 
|      | 
|     } | 
|   | 
|    | 
| } |