/// <summary> /// Reimports all assets at <paramref name="path"/> where the preset in <paramref name="applicableConfig"/> applies. /// </summary> /// <param name="path"></param> /// <param name="applicableConfig"></param> public static void ReimportAllAssets(string path, AutoPresetConfig applicableConfig) { var projectPath = GetProjectPath(); var fullPath = Path.Combine(projectPath, path); var assetPaths = Directory.GetFiles(fullPath, WILDCARD_SEARCH, SearchOption.TopDirectoryOnly) .Where(x => !x.EndsWith(META_FILE_EXTENSION)) .Select(y => y.Replace(projectPath, string.Empty)); foreach (var assetPath in assetPaths) { var assetImporter = AssetImporter.GetAtPath(assetPath); if (assetImporter != null && applicableConfig.CanBeAppliedTo(assetImporter)) { AssetDatabase.ImportAsset(assetPath); } } }
/// <summary> /// Returns true if an <see cref="AutoPresetConfig"/> instance was found in the same folder as the /// asset that applies to it, otherwise false. If true, <paramref name="autoPreset"/> will be /// initialized with that value. /// </summary> /// <param name="autoPreset"></param> /// <returns></returns> private bool TryGetPresetAsset(out AutoPresetConfig autoPreset) { autoPreset = null; var parentFolder = AssetDatabaseTools.GetAssetParentFolderPath(assetPath); var autoPresetConfigs = AssetDatabaseTools.GetAllAutoPresetConfigs(new[] { parentFolder }); foreach (var autoPresetConfig in autoPresetConfigs) { if (!autoPresetConfig.CanBeAppliedTo(assetImporter)) { continue; } autoPreset = autoPresetConfig; return(true); } return(false); }