制作的過(guò)程中偶爾會(huì)遇到自帶的shader出現(xiàn)問(wèn)題需要批量替換,這時(shí)候如果一個(gè)個(gè)的去找很麻煩而且容易有遺漏挺据,我這里提供一個(gè)思路來(lái)批量替換,關(guān)鍵代碼如下:
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;
}
}
}
}