少年修仙传客户端基础资源
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Text.RegularExpressions;
 
public class TextureRefrenceFinder : EditorWindow
{
 
    static TextureRefrenceFinder window;
 
    [UnityEditor.MenuItem("美术工具/贴图引用查找工具")]
    static void Init()
    {
        window = GetWindow(typeof(TextureRefrenceFinder), false, "贴图引用查找工具") as TextureRefrenceFinder;
        window.Show();
        window.autoRepaintOnSceneChange = true;
    }
 
    static List<Texture> selectedTextures = new List<Texture>();
    static Texture selectedTexture;
 
    static bool findAllMaterials = false;
    static List<Material> allMaterials = new List<Material>();
    static List<Material> refrenceMaterials = new List<Material>();
 
    [MenuItem("Assets/选择图片")]
    public static void SetSelectedTextures()
    {
        var assets = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
        var total = assets.Length;
        var index = 0;
 
        try
        {
            selectedTextures.Clear();
            foreach (var asset in assets)
            {
                var assetPath = AssetDatabase.GetAssetPath(asset);
                var texture = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture));
                if (texture != null)
                {
                    selectedTextures.Add((Texture)texture);
                }
 
                index++;
 
                EditorUtility.DisplayProgressBar("查找图片", assetPath, index / (float)total);
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }
        finally
        {
            selectedTexture = selectedTextures != null && selectedTextures.Count > 0 ? selectedTextures[0] : null;
            EditorUtility.ClearProgressBar();
        }
    }
 
    Vector2 textureScrollViewPosition = Vector2.zero;
    Vector2 materialScrollViewPosition = Vector2.zero;
 
    private void OnGUI()
    {
        EditorGUILayout.BeginVertical();
 
        EditorGUILayout.LabelField("贴图");
        EditorGUILayout.Space();
 
        if (selectedTextures != null && selectedTextures.Count > 0)
        {
            EditorGUI.indentLevel++;
            textureScrollViewPosition = EditorGUILayout.BeginScrollView(textureScrollViewPosition);
            foreach (var texture in selectedTextures)
            {
                DrawTexture(texture);
            }
            EditorGUILayout.EndScrollView();
 
            EditorGUI.indentLevel--;
        }
 
        EditorGUILayout.Space();
        if (GUILayout.Button("查找材质"))
        {
            if (!findAllMaterials)
            {
                FindAllMaterials();
            }
 
            FindRefreceMaterials(selectedTexture);
        }
 
        EditorGUILayout.Space();
 
        EditorGUILayout.LabelField("引用贴图的材质");
        EditorGUILayout.Space();
        if (refrenceMaterials != null && refrenceMaterials.Count > 0)
        {
            EditorGUI.indentLevel++;
            materialScrollViewPosition = EditorGUILayout.BeginScrollView(materialScrollViewPosition);
            foreach (var material in refrenceMaterials)
            {
                DrawMaterial(material);
            }
            EditorGUILayout.EndScrollView();
 
            EditorGUI.indentLevel--;
        }
 
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.EndVertical();
    }
 
    private void DrawTexture(Texture _texture)
    {
        if (_texture == null)
        {
            return;
        }
 
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.ObjectField(_texture.name, _texture, typeof(Texture), true);
        if (EditorGUILayout.Toggle(_texture != null && _texture == selectedTexture))
        {
            selectedTexture = _texture;
        }
        EditorGUILayout.EndHorizontal();
    }
 
    private void DrawMaterial(Material _material)
    {
        if (_material == null)
        {
            return;
        }
 
        EditorGUILayout.ObjectField(_material.name, _material, typeof(Material), true);
    }
 
    static void FindAllMaterials()
    {
        var path = Application.dataPath + "/Art";
        var allFiles = new DirectoryInfo(path).GetFiles("*", SearchOption.AllDirectories);
        var total = allFiles.Length;
        var index = 0;
 
        try
        {
            allMaterials.Clear();
            foreach (var file in allFiles)
            {
                var assetPath = "Assets" + file.FullName.Replace("\\", "/").Replace(Application.dataPath, "");
                var material = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Material));
                if (material != null)
                {
                    allMaterials.Add((Material)material);
                }
 
                index++;
                EditorUtility.DisplayProgressBar("初始化材质", assetPath, index / (float)total);
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }
        finally
        {
            findAllMaterials = true;
            EditorUtility.ClearProgressBar();
        }
    }
 
    static void FindRefreceMaterials(Texture _texture)
    {
        refrenceMaterials.Clear();
        if (_texture == null)
        {
            return;
        }
 
        var guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(_texture));
        var total = allMaterials.Count;
        var index = 0;
 
        try
        {
            foreach (var material in allMaterials)
            {
                var text = File.ReadAllText(AssetDatabase.GetAssetPath(material));
                if (!string.IsNullOrEmpty(text) && Regex.IsMatch(text, guid))
                {
                    refrenceMaterials.Add(material);
 
                    break;
                }
 
                index++;
 
                EditorUtility.DisplayProgressBar("查找引用材质", material.name, index / (float)total);
            }
        }
        catch (Exception ex)
        {
            Debug.Log(ex);
        }
        finally
        {
            EditorUtility.ClearProgressBar();
        }
 
    }
 
}