少年修仙传客户端基础资源
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System;
using System.Text;
 
public class IconNameNormalizeTool
{
    static string rootPath = Application.dataPath + "/ResourcesOut/UI/Sprite/FabaoIcon";
    static string spriteRelativePath = "Assets/ResourcesOut/UI/Sprite/";
 
    static string textPath = Application.dataPath + "/ResourcesOut/Refdata/Config/Icon.txt";
    static Dictionary<string, Dictionary<string, string>> iconNameDictionary = new Dictionary<string, Dictionary<string, string>>();
 
    static string[] headLines = new string[3];
 
    public static void IconNameNormalize()
    {
        try
        {
            ParseConfig();
            RenameSprites();
            WriteIconConfig();
        }
        catch (Exception ex)
        {
            Debug.Log("资源替换异常:" + ex);
        }
        finally
        {
            EditorUtility.ClearProgressBar();
        }
    }
 
    static void ParseConfig()
    {
        var lines = File.ReadAllLines(textPath);
 
        for (int i = 0; i < 3; i++)
        {
            headLines[i] = lines[i];
        }
 
        for (int i = 3; i < lines.Length; i++)
        {
            var line = lines[i];
            var valueStrings = line.Split('\t');
 
            for (int j = 0; j < valueStrings.Length; j++)
            {
                var folder = valueStrings[1];
                var key = valueStrings[0];
                var value = valueStrings[2];
 
                Dictionary<string, string> keyValues = null;
                if (!iconNameDictionary.ContainsKey(folder))
                {
                    iconNameDictionary[folder] = keyValues = new Dictionary<string, string>();
                }
                else
                {
                    keyValues = iconNameDictionary[folder];
                }
 
                keyValues[key] = value;
            }
        }
    }
 
    static void RenameSprites()
    {
        var allFiles = new DirectoryInfo(rootPath).GetFiles("*.png", SearchOption.AllDirectories);
 
        var total = allFiles.Length;
        var index = 0;
 
        foreach (var file in allFiles)
        {
            var fileInfo = new FileInfo(file.FullName);
            var pathStringArray = fileInfo.DirectoryName.Split('\\');
            var folderName = pathStringArray[pathStringArray.Length - 1];
 
            var prefix = StringUtility.Contact(folderName, "_");
            if (!file.Name.StartsWith(prefix))
            {
                var fileNameWithOutExtersion = file.Name.Replace(".png", "");
                var replaceName = StringUtility.Contact(prefix, fileNameWithOutExtersion);
                RenameAsset(StringUtility.Contact(spriteRelativePath, folderName, "/", file.Name), replaceName);
                ReplaceIconConfig(folderName, fileNameWithOutExtersion, replaceName);
            }
 
            index++;
 
            EditorUtility.DisplayProgressBar("替换图片名", "替换中.......", index / (float)total);
        }
 
        EditorUtility.ClearProgressBar();
    }
 
    static void WriteIconConfig()
    {
        var lines = new List<string>();
        lines.AddRange(headLines);
 
        foreach (var key in iconNameDictionary.Keys)
        {
            var keyValues = iconNameDictionary[key];
            foreach (var keyValue in keyValues)
            {
                lines.Add(StringUtility.Contact(keyValue.Key, "\t", key, "\t", keyValue.Value));
            }
        }
 
        File.WriteAllLines(textPath, lines.ToArray(), Encoding.UTF8);
    }
 
    private static void ReplaceIconConfig(string _folder, string _fileName, string _newFileName)
    {
        if (iconNameDictionary.ContainsKey(_folder))
        {
            var keyValues = iconNameDictionary[_folder];
 
            foreach (var key in keyValues.Keys)
            {
                if (keyValues[key] == _fileName)
                {
                    keyValues[key] = _newFileName;
                    break;
                }
            }
        }
 
    }
 
    static void RenameAsset(string _path, string _newName)
    {
        AssetDatabase.RenameAsset(_path, _newName);
    }
 
 
}