制作的过程中偶尔会遇到自带的shader出现问题需要批量替换,这时候如果一个个的去找很麻烦而且容易有遗漏,我这里提供一个思路来批量替换,关键代码如下:
static void ShaderSoftEdgeUnlit()
{
Shader shader = Shader.Find("Unlit/Soft Edge Unlit");
string[] tempMaterialsPath = AssetDatabase.GetAllAssetPaths();
List<Material> tempMaterials = new List<Material>();
for (int i = 0; i < tempMaterialsPath.Length; i++)
{
string ext = Path.GetExtension(tempMaterialsPath[i]);
if (ext != ".mat")
{
continue;
}
tempMaterials.Add(AssetDatabase.LoadAssetAtPath(tempMaterialsPath[i], typeof (Material)) as Material);
}
if (tempMaterials.Count != 0)
{
for (int i = 0; i < tempMaterials.Count; i++)
{
if (tempMaterials[i] == null)
{
continue;
}
if (tempMaterials[i].shader.name == "Legacy Shaders/Transparent/Cutout/Soft Edge Unlit")
{
tempMaterials[i].shader = shader;
}
}
}
}
网友评论