public static Material[] CopySPBRMaterialsAndTexturesToDst(MeshRenderer mr, string dstDirectory, System.Func <MaterialInfo, Material> func) { if (mr) { MaterialInfo[] matInfos = GraphicsUtili.Get_MaterialInfo(mr, " "); if (matInfos != null) { Material[] materials = new Material[matInfos.Length]; for (int i = 0; i < matInfos.Length; i++) { MaterialInfo info = matInfos[i]; string materialPath = ToUnity(dstDirectory + "/" + info.matName + ".mat"); Material material = AssetDatabase.LoadAssetAtPath <Material>(materialPath); if (material == null) { if (func == null) { material = new Material(Shader.Find("MSO/Standard/SPBR")); } else { material = func(info); } material.SetTexture("_MainTex", TextureUtil.CopyTextureToDest(info.path_D, dstDirectory)); material.SetTexture("_BumpMap", TextureUtil.CopyTextureToDest(info.path_N, dstDirectory)); AssetDatabase.CreateAsset(material, materialPath); AssetDatabase.Refresh(); } materials[i] = material; } return(materials); } else { return(null); } } else { return(null); } }
public static Material[] CopyMaterialsToDst(MeshRenderer mr, string dstDirectory, System.Func <MaterialInfo, Material> func) { if (mr) { MaterialInfo[] materialInfos = GraphicsUtili.Get_MaterialInfo(mr, "_PBRTexture"); if (materialInfos != null) { Material[] materials = new Material[materialInfos.Length]; for (int i = 0; i < materials.Length; i++) { MaterialInfo info = materialInfos[i]; bool spbr = false; if (info.path_P == null) { spbr = true; } else { if (info.path_P.Length <= 0) { spbr = true; } } string materialPath = ToUnity(dstDirectory + "/" + info.matName + ".mat"); Material material = AssetDatabase.LoadAssetAtPath <Material>(materialPath); if (material == null) { if (func == null) { if (spbr) { material = new Material(Shader.Find("MSO/Standard/SPBR")); } else { material = new Material(Shader.Find("MSO/Standard/PBR")); } } else { material = func(info); } string sourceD = VIO.UnitySlash(info.path_D); Texture diffuseTex = AssetDatabase.LoadAssetAtPath <Texture>(sourceD); material.SetTexture("_MainTex", diffuseTex); string sourceN = VIO.UnitySlash(info.path_N); Texture normalTex = AssetDatabase.LoadAssetAtPath <Texture>(sourceN); material.SetTexture("_BumpMap", normalTex); string sourceP = VIO.UnitySlash(info.path_P); Texture pbrTex = AssetDatabase.LoadAssetAtPath <Texture>(sourceP); material.SetTexture("_MetallicGlossMap", pbrTex); AssetDatabase.CreateAsset(material, materialPath); AssetDatabase.Refresh(); } materials[i] = material; } return(materials); } } return(null); }