static void AssignMaterialRemaps(SyncPrefabScriptedImporter importer) { if (importer) { // find all ScriptableObject based remaps if (!AssetDatabase.IsValidFolder("Assets/Reflect")) { return; } List <MaterialMappings> remappers = new List <MaterialMappings>(); foreach (string guid in AssetDatabase.FindAssets("t:MaterialMappings", new string[] { "Assets/Reflect" })) { var remapper = AssetDatabase.LoadAssetAtPath <MaterialMappings>(AssetDatabase.GUIDToAssetPath(guid)); //if (remapper.enabled) remappers.Add(remapper); } // sort remaps by priority (to prioritize conflicting remaps) //remappers.Sort((a, b) => a.priority.CompareTo(b.priority)); // for every material names, loop through remaps to find an override Dictionary <string, Material> remaps; importer.GetRemaps(out remaps); var names = importer.GetRemapNames(); foreach (string name in names) { foreach (MaterialMappings remapper in remappers) { var remapperNames = remapper.materialNames; if (remapperNames.Contains(name) && (remaps[name] == null /* || remapper.overwrite*/)) { //Debug.Log(string.Format("{0} => {1}", name, remapper.materialRemaps[remapperNames.FindIndex(x => x == name)].remappedMaterial)); remaps[name] = remapper[remapperNames.FindIndex(x => x == name)].remappedMaterial; break; } } } // assign override importer.SetRemaps(remaps); } }
internal static void ExtractMaterialFromSyncPrefabImporter(SyncPrefabScriptedImporter importer, int materialIndex) { var materialName = importer.GetRemapNames()[materialIndex]; var targetPath = EditorUtility.SaveFilePanel( "Save Extracted Material as", Application.dataPath, materialName, "mat"); if (targetPath == string.Empty) { return; } // issue error if path is outside of Project's Assets if (!targetPath.StartsWith(Application.dataPath)) { Debug.LogError("Cannot save materials outside of project's assets folder!"); return; } targetPath = "Assets" + targetPath.Substring(Application.dataPath.Length); System.Action <Material> postAction = ReflectEditorPreferences.convertExtractedMaterials ? materialConversions[(int)ReflectEditorPreferences.extractedMaterialsConverionMethod] : null; importer.ExtractMaterial(materialName, targetPath, ReflectEditorPreferences.dontExtractRemappedMaterials, ReflectEditorPreferences.autoAssignRemapsOnExtract, postAction); }