需求:为美术人员提供的工具,便于查找,旨在提高工作效率
功能点:Unity编辑器扩展
用于定位某一个指定的Shader材质:
[MenuItem(@"Tools/查找Shader名为Standard的材质球", false, 91)]
private static void FindMaterials()
{
var fbxs = AssetDatabase.FindAssets($"t:prefab", new string[] { "Assets/LoadableRes"});
List<UnityEngine.Object> assets = new List<UnityEngine.Object>();
var index = 0;
var cancel = false;
var data = Story.Model.LoadData<libcore.DunGeonDetail>(nameof(libcore.Dungeon_DunGeonDetail));
foreach (var fbx in fbxs)
{
++index;
var path = AssetDatabase.GUIDToAssetPath(fbx);
if (EditorUtility.DisplayCancelableProgressBar("查找prefab", path, index * 1f / fbxs.Length))
{
cancel = true;
break;
}
var fbxObj = AssetDatabase.LoadAssetAtPath<UnityEngine.GameObject>(path);
if (fbxObj == null)
continue;
var renderlist = fbxObj.GetComponentsInChildren<MeshRenderer>();
if (renderlist == null || renderlist.Length == 0)
{
continue;
}
foreach (var render in renderlist)
{
var mt = render.sharedMaterial;
if (mt == null) continue;
var shader = mt.shader.name;
if (mt.shader.name == "Standard")
{
if (!assets.Contains(fbxObj))
{
assets.Add(fbxObj);
}
UnityEngine.Debug.Log($"{path},{render.name}", fbxObj);
}
}
}
EditorUtility.ClearProgressBar();
if (!cancel)
{
EditorUtility.DisplayDialog("温馨提示", "查找完毕,单击控制错误信息,定位材质球", "确定");
}
else
{
UnityEngine.Debug.LogError("已取消");
}
}