Save asset importer settings if asset importer is dirty.
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { FindOptionProperties(props); layerMaskMapProperty = FindProperty(kLayerMaskMap, props); layerCountProperty = FindProperty(kLayerCount, props); m_MaterialEditor = materialEditor; m_MaterialEditor.serializedObject.Update(); Material material = m_MaterialEditor.target as Material; AssetImporter materialImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(material.GetInstanceID())); InitializeMaterialLayers(materialImporter); bool optionsChanged = false; EditorGUI.BeginChangeCheck(); { ShaderOptionsGUI(); EditorGUILayout.Space(); } if (EditorGUI.EndChangeCheck()) { optionsChanged = true; } bool layerChanged = LayersGUI(materialImporter); CheckLayerConsistency(); if (layerChanged || optionsChanged) { SynchronizeInputOptions(); foreach (var obj in m_MaterialEditor.targets) { SetupMaterial((Material)obj); SetupMaterialForLayers((Material)obj); } SaveMaterialLayers(materialImporter); } m_MaterialEditor.serializedObject.ApplyModifiedProperties(); if (layerChanged) { materialImporter.SaveAndReimport(); } }
static void MenuRemoveAB() { AssetDatabase.RemoveUnusedAssetBundleNames(); List <string> fileList = new List <string>(); List <string> fileRemove = new List <string>(); /// 遍历 目录 操作 if (null != Selection.objects) { for (int index = 0; index < Selection.objects.Length; index++) { if (null != Selection.objects[index]) { string path = string.Format("{0}/../{1}", Application.dataPath, AssetDatabase.GetAssetPath(Selection.objects[index])); if (System.IO.Directory.Exists(path)) { EditorSearchFile.SearchPath(path, fileList, ""); } else { fileList.Add(path); } } } } /// 资源剔除处理 RemoveSameAndUnExportAssets(fileList, fileRemove); /// 打印 LOG for (int index = 0; index < fileList.Count; index++) { UnityEditor.AssetImporter importer = UnityEditor.AssetImporter.GetAtPath("Assets" + fileList[index].Substring(fileList[index].IndexOf("/Resources-/"))); if (null == importer) { continue; } /// 为空返回 if (string.IsNullOrEmpty(importer.assetBundleName) && string.IsNullOrEmpty(importer.assetBundleVariant)) { continue; } /// 设置 Debug.Log(string.Format("Remove AssetBundle : {0}.{1}", importer.assetBundleName, importer.assetBundleVariant)); importer.SetAssetBundleNameAndVariant("", ""); importer.SaveAndReimport(); } for (int index = 0; index < fileRemove.Count; index++) { UnityEditor.AssetImporter importer = UnityEditor.AssetImporter.GetAtPath("Assets" + fileRemove[index].Substring(fileRemove[index].IndexOf("/Resources-/"))); if (null == importer) { continue; } /// 没设置 返回 if (string.IsNullOrEmpty(importer.assetBundleName) && string.IsNullOrEmpty(importer.assetBundleVariant)) { continue; } /// 的是依赖 返回 if (importer.assetBundleName.StartsWith("d/")) { continue; } /// 设置 Debug.LogError(string.Format("Remove AssetBundle : {0}.{1}", importer.assetBundleName, importer.assetBundleVariant)); importer.SetAssetBundleNameAndVariant("", ""); importer.SaveAndReimport(); } }