public static Texture CopyTextureToDest(string path, string dstDirectory) { string sourceD = VIO.UnitySlash(path); Texture sourceDTex = AssetDatabase.LoadAssetAtPath <Texture>(sourceD); if (sourceDTex != null) { string dstD = dstDirectory + "/" + System.IO.Path.GetFileName(sourceD); VIO.CopyBinaryFile(sourceD, dstD); AssetDatabase.Refresh(); Texture dstTex = VIO.TextureUtil.GetTexture(dstD); return(dstTex); } 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); }