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;
|
}
|
}
|
|
}
|