@@ -238,38 +238,41 @@ internal static Dictionary<string, string> FindAssetPathsForLineIDs(IEnumerable<
238238 var allFiles = Directory . EnumerateFiles ( assetsFolderPath , "*" , SearchOption . AllDirectories )
239239 . Where ( path => path . EndsWith ( ".meta" ) == false )
240240 . Where ( path => assetType . IsAssignableFrom ( AssetDatabase . GetMainAssetTypeAtPath ( path ) ) ) ;
241-
241+
242242 // Match files with those whose filenames contain a line ID
243- var matchedFilesAndPaths = lineIDs . GroupJoin (
244- // the elements we're matching lineIDs to
245- allFiles ,
246- // the key for lineIDs (being strings, it's just the line ID
247- // itself)
248- lineID => lineID ,
249- // the key for assets (the filename without the path)
250- assetPath => Path . GetFileName ( assetPath ) ,
251- // the way we produce the result (a key-value pair)
252- ( lineID , assetPaths ) =>
243+ // If a direct file match is found prefer that
244+ Dictionary < string , string > assets = new ( ) ;
245+ foreach ( var lineID in lineIDs )
246+ {
247+ var lineIDWithoutPrefix = lineID . Replace ( "line:" , "" ) . ToLowerInvariant ( ) ;
248+ var candidates = new List < string > ( ) ;
249+ foreach ( var asset in allFiles )
253250 {
254- if ( assetPaths . Count ( ) > 1 )
251+ var file = Path . GetFileNameWithoutExtension ( asset ) . ToLowerInvariant ( ) ;
252+
253+ if ( file == lineIDWithoutPrefix )
254+ {
255+ assets [ lineIDWithoutPrefix ] = asset ;
256+ break ;
257+ }
258+
259+ if ( file . Contains ( lineIDWithoutPrefix ) )
255260 {
256- Debug . LogWarning ( $ "Line { lineID } has { assetPaths . Count ( ) } possible assets. \n { string . Join ( ", " , assetPaths ) } " ) ;
261+ candidates . Add ( asset ) ;
257262 }
258- return new { lineID , assetPaths } ;
259- } ,
260- // the way we test to see if two elements should be joined (does
261- // the filename contain the line ID?)
262- Compare . By < string > ( ( fileName , lineID ) =>
263+ }
264+
265+ var count = candidates . Count ( ) ;
266+ if ( count > 0 )
263267 {
264- var lineIDWithoutPrefix = lineID . Replace ( "line:" , "" ) ;
265- return Path . GetFileNameWithoutExtension ( fileName ) . Contains ( lineIDWithoutPrefix ) ;
266- } )
267- )
268- // Discard any pair where no asset was found
269- . Where ( pair => pair . assetPaths . Count ( ) > 0 )
270- . ToDictionary ( entry => entry . lineID , entry => entry . assetPaths . FirstOrDefault ( ) ) ;
271-
272- return matchedFilesAndPaths ;
268+ assets [ lineID ] = candidates . FirstOrDefault ( ) ;
269+ if ( count > 1 )
270+ {
271+ Debug . LogWarning ( $ "Discovered { count } candidates for { lineID } . Selecting one.") ;
272+ }
273+ }
274+ }
275+ return assets ;
273276 }
274277
275278 /// <summary>
0 commit comments