少年修仙传客户端基础资源
client_Wu Xijin
2019-01-16 d53a782e2fd91ffc47dad0dd5a080ee451a351b7
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
using System.IO;
using System;
 
public class WindowImageCheck
{
    static string windowRootPath = Application.dataPath + "/ResourcesOut/UI/Window";
    static string windowRootPath2 = Application.dataPath + "/ResourcesOut/UI/PriorityWindow";
    static string prefabRootPath = Application.dataPath + "/ResourcesOut/UI/Prefab";
 
    [MenuItem("策划工具/查找和移除无用的Image")]
    public static void CheckAndReplaceFontSwitch()
    {
        try
        {
            var allFiles = new List<FileInfo>();
            allFiles.AddRange(new DirectoryInfo(windowRootPath).GetFiles("*.prefab", SearchOption.TopDirectoryOnly));
            allFiles.AddRange(new DirectoryInfo(windowRootPath2).GetFiles("*.prefab", SearchOption.TopDirectoryOnly));
            allFiles.AddRange(new DirectoryInfo(prefabRootPath).GetFiles("*.prefab", SearchOption.TopDirectoryOnly));
 
            var count = allFiles.Count;
            var index = 0;
 
            foreach (var file in allFiles)
            {
                var assetPath = file.FullName.Replace("\\", "/").Replace(Application.dataPath, "Assets");
                var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
 
                var images = prefab.GetComponentsInChildren<Image>(true);
                foreach (var image in images)
                {
                    if (image != null)
                    {
                        if (!image.enabled || image.color.a == 0f)
                        {
                            path = string.Empty;
                            Debug.Log(GetComponentPath(image.transform, ref path));
                            MonoBehaviour.DestroyImmediate(image, true);
                        }
                    }
                }
 
                index++;
                EditorUtility.SetDirty(prefab);
                EditorUtility.DisplayProgressBar("检测和移除Image", StringUtility.Contact("正在检测:", prefab.name), (float)index / count);
            }
 
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
 
            EditorUtility.ClearProgressBar();
        }
        catch (Exception ex)
        {
            Debug.Log(ex);
        }
 
    }
 
    static string path;
    private static string GetComponentPath(Transform _transform, ref string _path)
    {
        path = _transform.gameObject.name + path;
        if (_transform.parent != null)
        {
            path = "/" + path;
            return GetComponentPath(_transform.parent, ref _path);
        }
        else
        {
            return path;
        }
    }
 
}