步骤:
1.拿到所有shader资源路径
2、用AssetDatabase.GetDenpendencies(path)拿到shader依赖文件路径
3、判断这些路径有没有是图片格式的 png tga bit jmp
4、如果有说明这个shader带有默认贴图 应该去掉 贴图应该加在Material上
代码:
using UnityEngine;
using System.Collections;
using UnityEditor;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
public class FindShaderWithTextureWindow : EditorWindow {
[MenuItem("Tools/检查/检查带有默认贴图的shader")]
private static void FindShaderWithTexture()
{
GetWindow<FindShaderWithTextureWindow>().Show();
Find();
}
private static List<UnityEngine.Object> res = new List<UnityEngine.Object>();
private static void Find()
{
res.Clear();
var allfiles = Directory.GetFiles("Assets/", "*.shader", SearchOption.AllDirectories);
foreach (var file in allfiles)
{
foreach (var item in AssetDatabase.GetDependencies(file).Where(s => s.IsTexture()))
{
res.Add(AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(file));
break;
}
}
EditorUtility.DisplayDialog("", "就绪", "OK");
}
private Vector2 scro = Vector2.zero;
private void OnGUI()
{
scro = EditorGUILayout.BeginScrollView(scro);
EditorGUILayout.BeginVertical();
foreach (var item in res)
{
EditorGUILayout.ObjectField(item, typeof(UnityEngine.Object), true);
}
EditorGUILayout.EndVertical();
EditorGUILayout.EndScrollView();
}
}
public static class Extension
{
public static bool IsTexture(this string s)
{
return s.EndsWith("tga", true, System.Globalization.CultureInfo.CurrentCulture) ||
s.EndsWith("png", true, System.Globalization.CultureInfo.CurrentCulture) ||
s.EndsWith("jpg", true, System.Globalization.CultureInfo.CurrentCulture) ||
s.EndsWith("bmp", true, System.Globalization.CultureInfo.CurrentCulture);
}
public static void Addd(this Dictionary<object,List<object>> dic,object o1,object o2)
{
if (dic.ContainsKey(o1))
{
if (!dic[o1].Contains(o2))
{
dic[o1].Add(o2);
}
}else
{
dic.Add(o1, new List<object>() { o2 });
}
}
}