// Given a list of asset references, remove duplicate bundle references, and eliminate any explicit references to things inside bundles // NOTE: Will not eliminate references that show up twice inside different bundles private IEnumerable <AssetTag> EliminateDuplicatesAndResolveUrls(IEnumerable <AssetTag> refs) { List <AssetTag> firstPass = new List <AssetTag>(); HashSet <string> pathMap = new HashSet <string>(); HashSet <string> bundledContents = new HashSet <string>(); IBundleResolver resolver = Resolver; // first eliminate any duplicate paths foreach (AssetTag asset in refs) { // Leave static assets alone if (asset.IsStaticAsset) { firstPass.Add(asset); continue; } string path = asset.Value; if (!pathMap.Contains(path)) { // Need to crack open bundles to look at its contents for the second pass if (resolver.IsBundleVirtualPath(path)) { IEnumerable <string> contents = resolver.GetBundleContents(path); foreach (string filePath in contents) { bundledContents.Add(ResolveVirtualPath(filePath)); } // Also need to resolve the bundle url to get the unique version asset.Value = resolver.GetBundleUrl(path); firstPass.Add(asset); } // Non bundles we want to resolve the path and check its not a duplicate before adding else { string resolvedPath = ResolveVirtualPath(path); if (!pathMap.Contains(resolvedPath)) { pathMap.Add(resolvedPath); asset.Value = resolvedPath; firstPass.Add(asset); } } pathMap.Add(path); } } // Second pass to eliminate files that are contained inside of bundles return(firstPass.Where(asset => asset.IsStaticAsset || !bundledContents.Contains(asset.Value))); }