[MenuItem("Tools/检测image_texture是否丢失")]
public static void CheckImageMissing()
{
string[] allPath = AssetDatabase.FindAssets("t:Prefab", new string[] { "Assets/Resources" });
for (int i = 0; i < allPath.Length; i++)
{
string path = AssetDatabase.GUIDToAssetPath(allPath[i]);
var obj = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
if (obj != null)
{
var images = obj.GetComponentsInChildren<Image>();
int count1 = 0;
foreach (var item in images)
{
if (item.sprite == null)
{
count1 += 1;
string componentName = GetPath(item.transform, item.name);
Debug.LogError(count1 + " missing image: " + componentName);
}
}
var raw = obj.GetComponentsInChildren<RawImage>();
int count2 = 0;
foreach (var item in raw)
{
if (item.texture == null)
{
count2 += 1;
string componentName = GetPath(item.transform, item.name);
Debug.LogError(count1 + " missing raw image: " + componentName);
}
}
}
}
}
static string GetPath(Transform transform, string originName)
{
if (transform.parent == null)
{
return originName;
}
else
{
string tmpName = transform.parent.name + "/" + originName;
return GetPath(transform.parent, tmpName);
}
}