@@ -87,16 +87,26 @@ internal static void OnPostprocessAllAssets(
8787 }
8888
8989 var packagesConfigFilePath = ConfigurationManager . NugetConfigFile . PackagesConfigFilePath ;
90- var foundPackagesConfigAsset = importedAssets . Any (
91- importedAsset => Path . GetFullPath ( importedAsset ) . Equals ( packagesConfigFilePath , StringComparison . Ordinal ) ) ;
92-
93- if ( ! foundPackagesConfigAsset )
90+ if ( importedAssets . Any (
91+ path => path . EndsWith ( PackagesConfigFile . FileName ) &&
92+ Path . GetFullPath ( path ) . Equals ( packagesConfigFilePath , StringComparison . Ordinal ) ) )
9493 {
95- return ;
94+ InstalledPackagesManager . ReloadPackagesConfig ( ) ;
95+ PackageRestorer . Restore ( ConfigurationManager . NugetConfigFile . SlimRestore ) ;
9696 }
9797
98- InstalledPackagesManager . ReloadPackagesConfig ( ) ;
99- PackageRestorer . Restore ( ConfigurationManager . NugetConfigFile . SlimRestore ) ;
98+ var absoluteRepositoryPath = GetNuGetRepositoryPath ( ) ;
99+
100+ AssetDatabase . StartAssetEditing ( ) ;
101+
102+ try
103+ {
104+ LogResults ( importedAssets . SelectMany ( assetPath => HandleAsset ( assetPath , absoluteRepositoryPath , true ) ) ) ;
105+ }
106+ finally
107+ {
108+ AssetDatabase . StopAssetEditing ( ) ;
109+ }
100110 }
101111
102112 [ NotNull ]
@@ -128,7 +138,7 @@ internal static void OnPostprocessAllAssets(
128138 var assetPathComponents = GetPathComponents ( assetPathRelativeToRepository ) ;
129139 var packageNameParts = assetPathComponents . Length > 0 ? assetPathComponents [ 0 ] . Split ( '.' ) : Array . Empty < string > ( ) ;
130140 var packageName = string . Join ( "." , packageNameParts . TakeWhile ( part => ! part . All ( char . IsDigit ) ) ) ;
131- var packageConfig = InstalledPackagesManager . PackagesConfigFile . GetPackageConfigurationById ( packageName ) ;
141+ var configurationOfPackage = InstalledPackagesManager . PackagesConfigFile . GetPackageConfigurationById ( packageName ) ;
132142
133143 if ( ! GetPluginImporter ( projectRelativeAssetPath , out var plugin ) )
134144 {
@@ -144,26 +154,37 @@ internal static void OnPostprocessAllAssets(
144154 yield break ;
145155 }
146156
147- if ( packageConfig != null )
157+ var assetLablesToSet = new List < string > ( ) ;
158+ if ( configurationOfPackage != null )
148159 {
149- ModifyImportSettingsOfGeneralPlugin ( packageConfig , plugin , reimport ) ;
160+ assetLablesToSet . AddRange ( ModifyImportSettingsOfGeneralPlugin ( configurationOfPackage , plugin ) ) ;
150161 yield return ( "GeneralSetting" , projectRelativeAssetPath , ResultStatus . Success ) ;
151162 }
152163
153164 if ( assetPathComponents . Length > 1 && assetPathComponents [ 1 ] . Equals ( AnalyzersFolderName , StringComparison . OrdinalIgnoreCase ) )
154165 {
155- ModifyImportSettingsOfRoslynAnalyzer ( plugin , reimport ) ;
166+ assetLablesToSet . AddRange ( ModifyImportSettingsOfRoslynAnalyzer ( plugin ) ) ;
156167 yield return ( "RoslynAnalyzer" , projectRelativeAssetPath , ResultStatus . Success ) ;
168+ }
169+ else if ( assetPathComponents . Length > 0 &&
170+ UnityPreImportedLibraryResolver . GetAlreadyImportedEditorOnlyLibraries ( )
171+ . Contains ( Path . GetFileNameWithoutExtension ( assetPathComponents [ assetPathComponents . Length - 1 ] ) ) )
172+ {
173+ assetLablesToSet . AddRange ( ModifyImportSettingsOfPlayerOnly ( plugin ) ) ;
174+ yield return ( "PlayerOnly" , projectRelativeAssetPath , ResultStatus . Success ) ;
175+ }
157176
177+ if ( assetLablesToSet . Count == 0 )
178+ {
158179 yield break ;
159180 }
160181
161- if ( assetPathComponents . Length > 0 &&
162- UnityPreImportedLibraryResolver . GetAlreadyImportedEditorOnlyLibraries ( )
163- . Contains ( Path . GetFileNameWithoutExtension ( assetPathComponents [ assetPathComponents . Length - 1 ] ) ) )
182+ AssetDatabase . SetLabels ( plugin , assetLablesToSet . Distinct ( ) . ToArray ( ) ) ;
183+
184+ if ( reimport )
164185 {
165- ModifyImportSettingsOfPlayerOnly ( plugin , reimport ) ;
166- yield return ( "PlayerOnly" , projectRelativeAssetPath , ResultStatus . Success ) ;
186+ // Persist and reload the change to the meta file
187+ plugin . SaveAndReimport ( ) ;
167188 }
168189 }
169190
@@ -228,7 +249,7 @@ private static NugetPackageVersion GetRoslynVersionNumberFromAnalyzerPath(string
228249 return string . IsNullOrEmpty ( versionString ) ? null : new NugetPackageVersion ( versionString ) ;
229250 }
230251
231- private static void ModifyImportSettingsOfRoslynAnalyzer ( [ NotNull ] PluginImporter plugin , bool reimport )
252+ private static string [ ] ModifyImportSettingsOfRoslynAnalyzer ( [ NotNull ] PluginImporter plugin )
232253 {
233254 plugin . SetCompatibleWithAnyPlatform ( false ) ;
234255 plugin . SetCompatibleWithEditor ( false ) ;
@@ -271,28 +292,15 @@ private static void ModifyImportSettingsOfRoslynAnalyzer([NotNull] PluginImporte
271292 }
272293 }
273294
274- AssetDatabase . SetLabels ( plugin , enableRoslynAnalyzer ? new [ ] { RoslynAnalyzerLabel , ProcessedLabel } : new [ ] { ProcessedLabel } ) ;
275-
276- if ( reimport )
277- {
278- // Persist and reload the change to the meta file
279- plugin . SaveAndReimport ( ) ;
280- }
281-
282295 NugetLogger . LogVerbose ( "Configured asset '{0}' as a Roslyn-Analyzer." , plugin . assetPath ) ;
296+ return enableRoslynAnalyzer ? new [ ] { RoslynAnalyzerLabel , ProcessedLabel } : new [ ] { ProcessedLabel } ;
283297 }
284298
285- private static void ModifyImportSettingsOfGeneralPlugin ( [ NotNull ] PackageConfig packageConfig , [ NotNull ] PluginImporter plugin , bool reimport )
299+ private static string [ ] ModifyImportSettingsOfGeneralPlugin ( [ NotNull ] PackageConfig packageConfig , [ NotNull ] PluginImporter plugin )
286300 {
287301 PluginImporterIsExplicitlyReferencedProperty . SetValue ( plugin , ! packageConfig . AutoReferenced ) ;
288302
289- AssetDatabase . SetLabels ( plugin , new [ ] { ProcessedLabel } ) ;
290-
291- if ( reimport )
292- {
293- // Persist and reload the change to the meta file
294- plugin . SaveAndReimport ( ) ;
295- }
303+ return new [ ] { ProcessedLabel } ;
296304 }
297305
298306 /// <summary>
@@ -301,21 +309,14 @@ private static void ModifyImportSettingsOfGeneralPlugin([NotNull] PackageConfig
301309 /// <seealso cref="UnityPreImportedLibraryResolver.GetAlreadyImportedEditorOnlyLibraries" />.
302310 /// </summary>
303311 /// <param name="plugin">The asset to edit.</param>
304- /// <param name="reimport">Whether or not to save and re-import the file.</param>
305- private static void ModifyImportSettingsOfPlayerOnly ( [ NotNull ] PluginImporter plugin , bool reimport )
312+ private static string [ ] ModifyImportSettingsOfPlayerOnly ( [ NotNull ] PluginImporter plugin )
306313 {
307314 plugin . SetCompatibleWithAnyPlatform ( true ) ;
308315 plugin . SetExcludeEditorFromAnyPlatform ( true ) ;
309316
310- AssetDatabase . SetLabels ( plugin , new [ ] { ProcessedLabel } ) ;
311-
312- if ( reimport )
313- {
314- // Persist and reload the change to the meta file
315- plugin . SaveAndReimport ( ) ;
316- }
317-
318317 NugetLogger . LogVerbose ( "Configured asset '{0}' as a Player Only." , plugin . assetPath ) ;
318+
319+ return new [ ] { ProcessedLabel } ;
319320 }
320321
321322 /// <summary>
0 commit comments