public static void RestoreAllMaterials(bool show_progressbar = false) { restoring_in_progress = true; if (!File.Exists(PATH.MATERIALS_BACKUP_FILE)) { BackupAllMaterials(); return; } if (show_progressbar) { EditorUtility.DisplayProgressBar("Restoring materials", "", 0); } Dictionary <string, string> materials_to_restore = FileHelper.LoadDictionaryFromFile(PATH.MATERIALS_BACKUP_FILE); int length = materials_to_restore.Count; int i = 0; foreach (KeyValuePair <string, string> keyvalue in materials_to_restore) { Material m = AssetDatabase.LoadAssetAtPath <Material>(AssetDatabase.GUIDToAssetPath(keyvalue.Key)); if (m == null) { continue; } if (MaterialShaderBroken(m)) { Shader s = Shader.Find(keyvalue.Value); if (s != null) { m.shader = s; } if (show_progressbar) { EditorUtility.DisplayProgressBar("Restoring materials", m.name, (float)(++i) / length); } } } if (show_progressbar) { EditorUtility.ClearProgressBar(); } restoring_in_progress = false; }