public static void CompileMaterial() { string path = EditorSelection.GetSelectedFolderPath(); Shader shader = GraphicsSettings.renderPipelineAsset ? GraphicsSettings.renderPipelineAsset.defaultShader : Shader.Find("Standard"); Material material = new Material(shader); Color color = Color.black; color.ToRandomColor(); material.color = color; ProjectWindowUtil.CreateAsset(material, $"{path}{Path.DirectorySeparatorChar}material.mat"); AssetDatabase.Refresh(); }
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(); }