private static void SetNormalMap(TextureKeywords textureKeywords, Texture texture, string assetPath, Material material) { if (ContainsKeyword(textureKeywords.NormalMapKeys, texture.name.ToLower())) { ImportAsNormalMap(assetPath); material.SetTexture(_BumpMap, texture); } }
public static void CompileMaterial() { string path = EditorSelection.GetSelectedFolderPath(); string materialName = string.Empty; string[] guids = AssetDatabase.FindAssets("t:texture2D", new[] { path }); if (guids.IsNull()) { Debug.LogWarning("Incorrect Folder Selected"); return; } TextureKeywords textureKeywords = Resources.Load <TextureKeywords>("TextureKeywords/texture-keywords"); if (!textureKeywords) { textureKeywords = ScriptableObject.CreateInstance <TextureKeywords>(); } CreateMaterial(out Material material); foreach (string guid in guids) { string assetPath = AssetDatabase.GUIDToAssetPath(guid); materialName = string.IsNullOrEmpty(materialName) ? "material.mat" : $"{Path.GetFileName(Path.GetDirectoryName(assetPath))}.mat"; Texture texture = AssetDatabase.LoadAssetAtPath <Texture>(assetPath); SetTextureMap(textureKeywords.BaseMapKeys, texture, material, _BaseMap); SetTextureMap(textureKeywords.MetallicMapKeys, texture, material, _MetallicGlossMap); SetTextureMap(textureKeywords.SpecularMapKeys, texture, material, _SpecGlossMap); SetTextureMap(textureKeywords.OcclusionMapKeys, texture, material, _OcclusionMap); SetNormalMap(textureKeywords, texture, assetPath, material); } ProjectWindowUtil.CreateAsset(material, $"{path}{Path.DirectorySeparatorChar}{materialName}"); AssetDatabase.Refresh(); }