少年修仙传客户端基础资源
dabaoji
2025-06-09 8ee0256378cbf5dbc9d76ed10b60b65a844ef4dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using UnityEngine.UI;
using vnxbqy.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();//关闭
 
 
            }
        };
 
    
    }
 
  
}