少年修仙传客户端基础资源
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
101
102
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using UnityEngine.UI;
using vnxbqy.UI;
using System.Text;
 
//批量导入文字到预制体的text中
//!!!需要注意预制体导入的index要和导出的一致,避免遇到同名时无法区分的问题
public class ImportPrefabsWords : EditorWindow {
 
 
    [MenuItem("策划工具/==批量导入预制体文字==", false)]
    private static void Export()
    {
 
        string writePath = "import.txt";
        if (!File.Exists(writePath))
        {
            return;
        }
 
        string[] lines = File.ReadAllLines(writePath, Encoding.UTF8);
 
        int startIndex = 0;
        int changeCnt = 0;
        EditorApplication.update = delegate () {
            if (startIndex >= lines.Length)
            {
                Debug.LogFormat("文字批量修改成功-- 检索{0}行,共替换{1}行", startIndex, changeCnt);
                EditorUtility.ClearProgressBar();
                EditorApplication.update = null;
                startIndex = 0;
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                return;
            }
            var lineStr = lines[startIndex];
            string[] info = lines[startIndex].Split('\t');
            startIndex++;
            if (info.Length != 5)
            {
                Debug.LogFormat("异常:长度不对--执行到:第{0}行 {1}", startIndex, lineStr);
                return;
            }
            string file = info[0];
            int index = int.Parse(info[1]);
            string name = info[2];
            string content = info[3].Replace("\r","").Replace("\n","");
 
            bool isCancel = EditorUtility.DisplayCancelableProgressBar("导入预制体文字-"+lines.Length, file, (float)startIndex / (float)lines.Length);
            GameObject _prefab = AssetDatabase.LoadAssetAtPath<GameObject>(file);
            if (_prefab == null)
            {
                if (isCancel) {
 
                    EditorUtility.ClearProgressBar();
                    EditorApplication.update = null;
                    startIndex = 0;
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                }
                Debug.LogFormat("异常:预制体异常--执行到:第{0}行 {1}", startIndex, lineStr);
                return;
            }
            Text[] transArr = _prefab.GetComponentsInChildren<Text>(true);
 
            Text item = transArr[index];
            if (item.name == name)
            {
                var curText = item.text.Replace("\r", "").Replace("\n", "");
                if (curText != content)
                {
                    item.text = content;
                    EditorUtility.SetDirty(_prefab);
                    changeCnt++;
                    //Debug.LogFormat("字体批量文件--{0} , {1}", file, index);
                 }
            }
            else
            {
                Debug.LogErrorFormat("异常:第{0}行替换失败{1},{2}", startIndex, file, name);
            }
 
            if (isCancel || startIndex >= lines.Length) 
            {
                Debug.LogFormat("文字批量修改成功-- 检索{0}行,共替换{1}行", startIndex, changeCnt);
                EditorUtility.ClearProgressBar();
                EditorApplication.update = null;
                startIndex = 0;
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
        };
 
    
    }
 
  
}