bool LoadCachedData(string path, out AssetLoadInfo assetInfo, out BuildUsageTagSet buildUsage, BuildUsageTagGlobal globalUsage) { assetInfo = default; buildUsage = default; if (!m_Parameters.UseCache || m_Cache == null) { return(false); } CacheEntry entry = GetCacheEntry(path, globalUsage); m_Cache.LoadCachedData(new List <CacheEntry> { entry }, out IList <CachedInfo> cachedInfos); var cachedInfo = cachedInfos[0]; if (cachedInfo != null) { assetInfo = (AssetLoadInfo)cachedInfo.Data[0]; buildUsage = (BuildUsageTagSet)cachedInfo.Data[1]; var objectTypes = (List <KeyValuePair <ObjectIdentifier, Type[]> >)cachedInfo.Data[2]; BuildCacheUtility.SetTypeForObjects(objectTypes); } else { GatherAssetData(path, out assetInfo, out buildUsage, globalUsage); cachedInfo = GetCachedInfo(entry, assetInfo, buildUsage); m_Cache.SaveCachedData(new List <CachedInfo> { cachedInfo }); } return(true); }
/// <inheritdoc /> public ReturnCode Run() { BuildUsageTagGlobal globalUsage = m_DependencyData.GlobalUsage; foreach (var sceneInfo in m_DependencyData.SceneInfo) { globalUsage |= sceneInfo.Value.globalUsage; } IList <CacheEntry> entries = m_WriteData.WriteOperations.Select(x => GetCacheEntry(x, m_Parameters.GetContentBuildSettings(), globalUsage)).ToList(); IList <CachedInfo> cachedInfo = null; IList <CachedInfo> uncachedInfo = null; if (m_Parameters.UseCache && m_Cache != null) { m_Cache.LoadCachedData(entries, out cachedInfo); uncachedInfo = new List <CachedInfo>(); } for (int i = 0; i < m_WriteData.WriteOperations.Count; i++) { IWriteOperation op = m_WriteData.WriteOperations[i]; WriteResult result; if (cachedInfo != null && cachedInfo[i] != null) { if (!m_Tracker.UpdateInfoUnchecked(string.Format("{0} (Cached)", op.Command.internalName))) { return(ReturnCode.Canceled); } result = (WriteResult)cachedInfo[i].Data[0]; } else { if (!m_Tracker.UpdateInfoUnchecked(op.Command.internalName)) { return(ReturnCode.Canceled); } var outputFolder = m_Parameters.TempOutputFolder; if (m_Parameters.UseCache && m_Cache != null) { outputFolder = m_Cache.GetCachedArtifactsDirectory(entries[i]); } Directory.CreateDirectory(outputFolder); result = op.Write(outputFolder, m_Parameters.GetContentBuildSettings(), globalUsage); if (uncachedInfo != null) { uncachedInfo.Add(GetCachedInfo(entries[i], op, result)); } } SetOutputInformation(op.Command.internalName, result); } if (m_Parameters.UseCache && m_Cache != null) { m_Cache.SaveCachedData(uncachedInfo); } return(ReturnCode.Success); }
/// <inheritdoc /> public ReturnCode Run() { IList <CachedInfo> cachedInfo = null; IList <CachedInfo> uncachedInfo = null; if (m_Parameters.UseCache && m_Cache != null) { IList <CacheEntry> entries = m_Content.Scenes.Select(x => m_Cache.GetCacheEntry(x, Version)).ToList(); m_Cache.LoadCachedData(entries, out cachedInfo); uncachedInfo = new List <CachedInfo>(); } for (int i = 0; i < m_Content.Scenes.Count; i++) { GUID scene = m_Content.Scenes[i]; string scenePath = AssetDatabase.GUIDToAssetPath(scene.ToString()); SceneDependencyInfo sceneInfo; BuildUsageTagSet usageTags; if (cachedInfo != null && cachedInfo[i] != null) { if (!m_Tracker.UpdateInfoUnchecked(string.Format("{0} (Cached)", scenePath))) { return(ReturnCode.Canceled); } sceneInfo = (SceneDependencyInfo)cachedInfo[i].Data[0]; usageTags = cachedInfo[i].Data[1] as BuildUsageTagSet; } else { if (!m_Tracker.UpdateInfoUnchecked(scenePath)) { return(ReturnCode.Canceled); } var references = new HashSet <ObjectIdentifier>(); string[] dependencies = AssetDatabase.GetDependencies(scenePath); foreach (var assetPath in dependencies) { var assetGuid = new GUID(AssetDatabase.AssetPathToGUID(assetPath)); if (ValidationMethods.ValidAsset(assetGuid) != ValidationMethods.Status.Asset) { continue; } // TODO: Use Cache to speed this up? var assetIncludes = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(assetGuid, m_Parameters.Target); var assetReferences = ContentBuildInterface.GetPlayerDependenciesForObjects(assetIncludes, m_Parameters.Target, m_Parameters.ScriptInfo); references.UnionWith(assetIncludes); references.UnionWith(assetReferences); } sceneInfo = new SceneDependencyInfo(); usageTags = new BuildUsageTagSet(); sceneInfo.SetScene(scenePath); sceneInfo.SetProcessedScene(scenePath); sceneInfo.SetReferencedObjects(references.ToArray()); if (uncachedInfo != null) { uncachedInfo.Add(GetCachedInfo(scene, sceneInfo.referencedObjects, sceneInfo, usageTags)); } } SetOutputInformation(scene, sceneInfo, usageTags); } if (m_Parameters.UseCache && m_Cache != null) { m_Cache.SaveCachedData(uncachedInfo); } return(ReturnCode.Success); }
public ReturnCode Run() { var globalUsage = m_DependencyData.GlobalUsage; foreach (SceneDependencyInfo sceneInfo in m_DependencyData.SceneInfo.Values) { globalUsage |= sceneInfo.globalUsage; } if (m_SpriteData == null) { m_SpriteData = new BuildSpriteData(); } IList <CachedInfo> cachedInfo = null; List <CachedInfo> uncachedInfo = null; if (m_Parameters.UseCache && m_Cache != null) { IList <CacheEntry> entries = m_Content.Assets.Select(m_Cache.GetCacheEntry).ToList(); m_Cache.LoadCachedData(entries, out cachedInfo); uncachedInfo = new List <CachedInfo>(); } for (int i = 0; i < m_Content.Assets.Count; i++) { GUID asset = m_Content.Assets[i]; string assetPath = AssetDatabase.GUIDToAssetPath(asset.ToString()); AssetLoadInfo assetInfo; BuildUsageTagSet usageTags; SpriteImporterData importerData; if (cachedInfo != null && cachedInfo[i] != null) { if (!m_Tracker.UpdateInfoUnchecked(string.Format("{0} (Cached)", assetPath))) { return(ReturnCode.Canceled); } assetInfo = cachedInfo[i].Data[0] as AssetLoadInfo; usageTags = cachedInfo[i].Data[1] as BuildUsageTagSet; importerData = cachedInfo[i].Data[2] as SpriteImporterData; } else { if (!m_Tracker.UpdateInfoUnchecked(assetPath)) { return(ReturnCode.Canceled); } assetInfo = new AssetLoadInfo(); usageTags = new BuildUsageTagSet(); importerData = null; assetInfo.asset = asset; var includedObjects = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(asset, m_Parameters.Target); assetInfo.includedObjects = new List <ObjectIdentifier>(includedObjects); var referencedObjects = ContentBuildInterface.GetPlayerDependenciesForObjects(includedObjects, m_Parameters.Target, m_Parameters.ScriptInfo); assetInfo.referencedObjects = new List <ObjectIdentifier>(referencedObjects); ContentBuildInterface.CalculateBuildUsageTags(referencedObjects, includedObjects, globalUsage, usageTags, m_DependencyData.DependencyUsageCache); var importer = AssetImporter.GetAtPath(assetPath) as TextureImporter; if (importer != null && importer.textureType == TextureImporterType.Sprite) { importerData = new SpriteImporterData(); importerData.PackedSprite = !string.IsNullOrEmpty(importer.spritePackingTag); importerData.SourceTexture = includedObjects.First(); } if (uncachedInfo != null) { uncachedInfo.Add(GetCachedInfo(asset, assetInfo, usageTags, importerData)); } } SetOutputInformation(asset, assetInfo, usageTags, importerData); } if (m_SpriteData.ImporterData.Count == 0) { m_SpriteData = null; } if (m_Parameters.UseCache && m_Cache != null) { m_Cache.SaveCachedData(uncachedInfo); } return(ReturnCode.Success); }
public static ReturnCode RunCachedOperation <T>(IBuildCache cache, IBuildLogger log, IProgressTracker tracker, List <WorkItem <T> > workItems, IRunCachedCallbacks <T> cbs ) { using (log.ScopedStep(LogLevel.Info, "RunCachedOperation")) { List <CacheEntry> cacheEntries = null; List <WorkItem <T> > nonCachedItems = workItems; var cachedItems = new List <WorkItem <T> >(); for (int i = 0; i < workItems.Count; i++) { workItems[i].Index = i; } IList <CachedInfo> cachedInfo = null; if (cache != null) { using (log.ScopedStep(LogLevel.Info, "Creating Cache Entries")) for (int i = 0; i < workItems.Count; i++) { workItems[i].entry = cbs.CreateCacheEntry(workItems[i]); } cacheEntries = workItems.Select(i => i.entry).ToList(); using (log.ScopedStep(LogLevel.Info, "Load Cached Data")) cache.LoadCachedData(cacheEntries, out cachedInfo); cachedItems = workItems.Where(x => cachedInfo[x.Index] != null).ToList(); nonCachedItems = workItems.Where(x => cachedInfo[x.Index] == null).ToList(); } using (log.ScopedStep(LogLevel.Info, "Process Entries")) foreach (WorkItem <T> item in nonCachedItems) { if (!tracker.UpdateInfoUnchecked(item.StatusText)) { return(ReturnCode.Canceled); } cbs.ProcessUncached(item); } using (log.ScopedStep(LogLevel.Info, "Process Cached Entries")) foreach (WorkItem <T> item in cachedItems) { cbs.ProcessCached(item, cachedInfo[item.Index]); } foreach (WorkItem <T> item in workItems) { cbs.PostProcess(item); } if (cache != null) { List <CachedInfo> uncachedInfo; using (log.ScopedStep(LogLevel.Info, "Saving to Cache")) { using (log.ScopedStep(LogLevel.Info, "Creating Cached Infos")) uncachedInfo = nonCachedItems.Select((item) => cbs.CreateCachedInfo(item)).ToList(); cache.SaveCachedData(uncachedInfo); } } log.AddEntrySafe(LogLevel.Info, $"Total Entries: {workItems.Count}, Processed: {nonCachedItems.Count}, Cached: {cachedItems.Count}"); return(ReturnCode.Success); } }
/// <inheritdoc /> public ReturnCode Run() { if (m_Content.Scenes.IsNullOrEmpty()) return ReturnCode.SuccessNotRun; IList<CachedInfo> cachedInfo = null; IList<CachedInfo> uncachedInfo = null; if (m_Parameters.UseCache && m_Cache != null) { IList<CacheEntry> entries = m_Content.Scenes.Select(x => m_Cache.GetCacheEntry(x, Version)).ToList(); m_Cache.LoadCachedData(entries, out cachedInfo); uncachedInfo = new List<CachedInfo>(); } BuildSettings settings = m_Parameters.GetContentBuildSettings(); for (int i = 0; i < m_Content.Scenes.Count; i++) { GUID scene = m_Content.Scenes[i]; string scenePath = AssetDatabase.GUIDToAssetPath(scene.ToString()); SceneDependencyInfo sceneInfo; BuildUsageTagSet usageTags; Hash128 prefabDependency = new Hash128(); if (cachedInfo != null && cachedInfo[i] != null) { if (!m_Tracker.UpdateInfoUnchecked(string.Format("{0} (Cached)", scenePath))) return ReturnCode.Canceled; sceneInfo = (SceneDependencyInfo)cachedInfo[i].Data[0]; usageTags = cachedInfo[i].Data[1] as BuildUsageTagSet; prefabDependency = (Hash128)cachedInfo[i].Data[2]; } else { if (!m_Tracker.UpdateInfoUnchecked(scenePath)) return ReturnCode.Canceled; usageTags = new BuildUsageTagSet(); #if UNITY_2019_3_OR_NEWER sceneInfo = ContentBuildInterface.CalculatePlayerDependenciesForScene(scenePath, settings, usageTags, m_DependencyData.DependencyUsageCache); #else string outputFolder = m_Parameters.TempOutputFolder; if (m_Parameters.UseCache && m_Cache != null) outputFolder = m_Cache.GetCachedArtifactsDirectory(m_Cache.GetCacheEntry(scene, Version)); Directory.CreateDirectory(outputFolder); sceneInfo = ContentBuildInterface.PrepareScene(scenePath, settings, usageTags, m_DependencyData.DependencyUsageCache, outputFolder); #endif if (uncachedInfo != null) { // We only need to gather prefab dependencies and calculate the hash if we are using caching, otherwise we can skip it var prefabEntries = AssetDatabase.GetDependencies(AssetDatabase.GUIDToAssetPath(scene.ToString())).Where(path => path.EndsWith(".prefab")).Select(m_Cache.GetCacheEntry); prefabDependency = HashingMethods.Calculate(prefabEntries).ToHash128(); uncachedInfo.Add(GetCachedInfo(scene, sceneInfo.referencedObjects, sceneInfo, usageTags, prefabEntries, prefabDependency)); } } SetOutputInformation(scene, sceneInfo, usageTags, prefabDependency); } if (m_Parameters.UseCache && m_Cache != null) m_Cache.SaveCachedData(uncachedInfo); return ReturnCode.Success; }
public ReturnCode Run() { Dictionary <string, ulong> fileOffsets = new Dictionary <string, ulong>(); List <KeyValuePair <string, List <ResourceFile> > > bundleResources; { Dictionary <string, List <ResourceFile> > bundleToResources = new Dictionary <string, List <ResourceFile> >(); foreach (var pair in m_Results.WriteResults) { string bundle = m_WriteData.FileToBundle[pair.Key]; List <ResourceFile> resourceFiles; bundleToResources.GetOrAdd(bundle, out resourceFiles); resourceFiles.AddRange(pair.Value.resourceFiles); foreach (ResourceFile serializedFile in pair.Value.resourceFiles) { if (!serializedFile.serializedFile) { continue; } ObjectSerializedInfo firstObject = pair.Value.serializedObjects.First(x => x.header.fileName == serializedFile.fileAlias); fileOffsets[serializedFile.fileName] = firstObject.header.offset; } } bundleResources = bundleToResources.ToList(); } Dictionary <string, HashSet <string> > bundleDependencies = new Dictionary <string, HashSet <string> >(); foreach (var files in m_WriteData.AssetToFiles.Values) { if (files.IsNullOrEmpty()) { continue; } string bundle = m_WriteData.FileToBundle[files.First()]; HashSet <string> dependencies; bundleDependencies.GetOrAdd(bundle, out dependencies); dependencies.UnionWith(files.Select(x => m_WriteData.FileToBundle[x])); dependencies.Remove(bundle); } IList <CacheEntry> entries = bundleResources.Select(x => GetCacheEntry(x.Key, x.Value, m_Parameters.GetCompressionForIdentifier(x.Key))).ToList(); IList <CachedInfo> cachedInfo = null; IList <CachedInfo> uncachedInfo = null; if (m_Parameters.UseCache && m_Cache != null) { m_Cache.LoadCachedData(entries, out cachedInfo); uncachedInfo = new List <CachedInfo>(); } for (int i = 0; i < bundleResources.Count; i++) { string bundleName = bundleResources[i].Key; ResourceFile[] resourceFiles = bundleResources[i].Value.ToArray(); BuildCompression compression = m_Parameters.GetCompressionForIdentifier(bundleName); string writePath; BundleDetails details; if (cachedInfo != null && cachedInfo[i] != null) { if (!m_Tracker.UpdateInfoUnchecked(string.Format("{0} (Cached)", bundleName))) { return(ReturnCode.Canceled); } details = (BundleDetails)cachedInfo[i].Data[0]; details.FileName = string.Format("{0}/{1}", m_Parameters.OutputFolder, bundleName); HashSet <string> dependencies; if (bundleDependencies.TryGetValue(bundleName, out dependencies)) { details.Dependencies = dependencies.ToArray(); } else { details.Dependencies = new string[0]; } writePath = string.Format("{0}/{1}", m_Cache.GetCachedArtifactsDirectory(entries[i]), bundleName); } else { if (!m_Tracker.UpdateInfoUnchecked(bundleName)) { return(ReturnCode.Canceled); } details = new BundleDetails(); writePath = string.Format("{0}/{1}", m_Parameters.TempOutputFolder, bundleName); if (m_Parameters.UseCache && m_Cache != null) { writePath = string.Format("{0}/{1}", m_Cache.GetCachedArtifactsDirectory(entries[i]), bundleName); } Directory.CreateDirectory(Path.GetDirectoryName(writePath)); details.FileName = string.Format("{0}/{1}", m_Parameters.OutputFolder, bundleName); details.Crc = ContentBuildInterface.ArchiveAndCompress(resourceFiles, writePath, compression); details.Hash = CalculateHashVersion(fileOffsets, resourceFiles); HashSet <string> dependencies; if (bundleDependencies.TryGetValue(bundleName, out dependencies)) { details.Dependencies = dependencies.ToArray(); } else { details.Dependencies = new string[0]; } if (uncachedInfo != null) { uncachedInfo.Add(GetCachedInfo(m_Cache, entries[i], resourceFiles, details)); } } SetOutputInformation(writePath, details.FileName, bundleName, details); } if (m_Parameters.UseCache && m_Cache != null) { m_Cache.SaveCachedData(uncachedInfo); } return(ReturnCode.Success); }
public ReturnCode Run() { var globalUsage = m_DependencyData.GlobalUsage; foreach (SceneDependencyInfo sceneInfo in m_DependencyData.SceneInfo.Values) { globalUsage |= sceneInfo.globalUsage; } if (m_SpriteData == null) { m_SpriteData = new BuildSpriteData(); } if (m_ExtendedAssetData == null) { m_ExtendedAssetData = new BuildExtendedAssetData(); } IList <CachedInfo> cachedInfo = null; List <CachedInfo> uncachedInfo = null; if (m_Parameters.UseCache && m_Cache != null) { IList <CacheEntry> entries = m_Content.Assets.Select(x => m_Cache.GetCacheEntry(x, Version)).ToList(); m_Cache.LoadCachedData(entries, out cachedInfo); uncachedInfo = new List <CachedInfo>(); } for (int i = 0; i < m_Content.Assets.Count; i++) { GUID asset = m_Content.Assets[i]; string assetPath = AssetDatabase.GUIDToAssetPath(asset.ToString()); AssetLoadInfo assetInfo; BuildUsageTagSet usageTags; SpriteImporterData importerData; ExtendedAssetData assetData; if (cachedInfo != null && cachedInfo[i] != null) { if (!m_Tracker.UpdateInfoUnchecked(string.Format("{0} (Cached)", assetPath))) { return(ReturnCode.Canceled); } assetInfo = cachedInfo[i].Data[0] as AssetLoadInfo; usageTags = cachedInfo[i].Data[1] as BuildUsageTagSet; importerData = cachedInfo[i].Data[2] as SpriteImporterData; assetData = cachedInfo[i].Data[3] as ExtendedAssetData; } else { if (!m_Tracker.UpdateInfoUnchecked(assetPath)) { return(ReturnCode.Canceled); } assetInfo = new AssetLoadInfo(); usageTags = new BuildUsageTagSet(); importerData = null; assetData = null; assetInfo.asset = asset; var includedObjects = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(asset, m_Parameters.Target); assetInfo.includedObjects = new List <ObjectIdentifier>(includedObjects); var referencedObjects = ContentBuildInterface.GetPlayerDependenciesForObjects(includedObjects, m_Parameters.Target, m_Parameters.ScriptInfo); assetInfo.referencedObjects = new List <ObjectIdentifier>(referencedObjects); var allObjects = new List <ObjectIdentifier>(includedObjects); allObjects.AddRange(referencedObjects); ContentBuildInterface.CalculateBuildUsageTags(allObjects.ToArray(), includedObjects, globalUsage, usageTags, m_DependencyData.DependencyUsageCache); var importer = AssetImporter.GetAtPath(assetPath) as TextureImporter; if (importer != null && importer.textureType == TextureImporterType.Sprite) { // Legacy Sprite Packing Modes if (EditorSettings.spritePackerMode == SpritePackerMode.AlwaysOn || EditorSettings.spritePackerMode == SpritePackerMode.BuildTimeOnly) { importerData = new SpriteImporterData(); importerData.PackedSprite = !string.IsNullOrEmpty(importer.spritePackingTag); importerData.SourceTexture = includedObjects.First(); } else if (!referencedObjects.IsNullOrEmpty()) // Sprite is referencing packed data { importerData = new SpriteImporterData(); importerData.PackedSprite = EditorSettings.spritePackerMode != SpritePackerMode.Disabled; importerData.SourceTexture = includedObjects.First(); } } var representations = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath); if (!representations.IsNullOrEmpty()) { assetData = new ExtendedAssetData(); foreach (var representation in representations) { if (AssetDatabase.IsMainAsset(representation)) { continue; } string guid; long localId; if (!AssetDatabase.TryGetGUIDAndLocalFileIdentifier(representation, out guid, out localId)) { continue; } assetData.Representations.AddRange(includedObjects.Where(x => x.localIdentifierInFile == localId)); } } if (uncachedInfo != null) { uncachedInfo.Add(GetCachedInfo(asset, assetInfo, usageTags, importerData, assetData)); } } SetOutputInformation(asset, assetInfo, usageTags, importerData, assetData); } if (m_SpriteData.ImporterData.Count == 0) { m_SpriteData = null; } if (m_ExtendedAssetData.ExtendedData.Count == 0) { m_SpriteData = null; } if (m_Parameters.UseCache && m_Cache != null) { m_Cache.SaveCachedData(uncachedInfo); } return(ReturnCode.Success); }
/// <inheritdoc /> public ReturnCode Run() { if (m_Content.Scenes.IsNullOrEmpty()) { return(ReturnCode.SuccessNotRun); } IList <CachedInfo> cachedInfo = null; IList <CachedInfo> uncachedInfo = null; if (m_Parameters.UseCache && m_Cache != null) { IList <CacheEntry> entries = m_Content.Scenes.Select(x => m_Cache.GetCacheEntry(x, Version)).ToList(); m_Cache.LoadCachedData(entries, out cachedInfo); uncachedInfo = new List <CachedInfo>(); } BuildSettings settings = m_Parameters.GetContentBuildSettings(); for (int i = 0; i < m_Content.Scenes.Count; i++) { GUID scene = m_Content.Scenes[i]; string scenePath = AssetDatabase.GUIDToAssetPath(scene.ToString()); SceneDependencyInfo sceneInfo; BuildUsageTagSet usageTags; if (cachedInfo != null && cachedInfo[i] != null) { if (!m_Tracker.UpdateInfoUnchecked(string.Format("{0} (Cached)", scenePath))) { return(ReturnCode.Canceled); } sceneInfo = (SceneDependencyInfo)cachedInfo[i].Data[0]; usageTags = cachedInfo[i].Data[1] as BuildUsageTagSet; } else { if (!m_Tracker.UpdateInfoUnchecked(scenePath)) { return(ReturnCode.Canceled); } usageTags = new BuildUsageTagSet(); #if UNITY_2019_3_OR_NEWER sceneInfo = ContentBuildInterface.CalculatePlayerDependenciesForScene(scenePath, settings, usageTags, m_DependencyData.DependencyUsageCache); #else string outputFolder = m_Parameters.TempOutputFolder; if (m_Parameters.UseCache && m_Cache != null) { outputFolder = m_Cache.GetCachedArtifactsDirectory(m_Cache.GetCacheEntry(scene, Version)); } Directory.CreateDirectory(outputFolder); sceneInfo = ContentBuildInterface.PrepareScene(scenePath, settings, usageTags, m_DependencyData.DependencyUsageCache, outputFolder); #endif if (uncachedInfo != null) { uncachedInfo.Add(GetCachedInfo(scene, sceneInfo.referencedObjects, sceneInfo, usageTags)); } } SetOutputInformation(scene, sceneInfo, usageTags); } if (m_Parameters.UseCache && m_Cache != null) { m_Cache.SaveCachedData(uncachedInfo); } return(ReturnCode.Success); }
/// <inheritdoc /> public ReturnCode Run() { if (m_Content.Scenes.IsNullOrEmpty()) { return(ReturnCode.SuccessNotRun); } IList <CachedInfo> cachedInfo = null; IList <CachedInfo> uncachedInfo = null; if (m_Parameters.UseCache && m_Cache != null) { IList <CacheEntry> entries = m_Content.Scenes.Select(x => GetSceneCacheEntry(x)).ToList(); m_Cache.LoadCachedData(entries, out cachedInfo); uncachedInfo = new List <CachedInfo>(); } BuildSettings settings = m_Parameters.GetContentBuildSettings(); for (int i = 0; i < m_Content.Scenes.Count; i++) { GUID scene = m_Content.Scenes[i]; string scenePath = AssetDatabase.GUIDToAssetPath(scene.ToString()); SceneDependencyInfo sceneInfo; BuildUsageTagSet usageTags; Hash128 prefabDependency = new Hash128(); if (cachedInfo != null && cachedInfo[i] != null) { if (!m_Tracker.UpdateInfoUnchecked(string.Format("{0} (Cached)", scenePath))) { return(ReturnCode.Canceled); } sceneInfo = (SceneDependencyInfo)cachedInfo[i].Data[0]; usageTags = cachedInfo[i].Data[1] as BuildUsageTagSet; prefabDependency = (Hash128)cachedInfo[i].Data[2]; var objectTypes = cachedInfo[i].Data[3] as List <ObjectTypes>; if (objectTypes != null) { BuildCacheUtility.SetTypeForObjects(objectTypes); } } else { if (!m_Tracker.UpdateInfoUnchecked(scenePath)) { return(ReturnCode.Canceled); } usageTags = new BuildUsageTagSet(); #if UNITY_2019_3_OR_NEWER #if NONRECURSIVE_DEPENDENCY_DATA if (m_Parameters.NonRecursiveDependencies) { sceneInfo = ContentBuildInterface.CalculatePlayerDependenciesForScene(scenePath, settings, usageTags, m_DependencyData.DependencyUsageCache, DependencyType.ValidReferences); ObjectIdentifier[] filteredReferences = sceneInfo.referencedObjects.ToArray(); filteredReferences = ExtensionMethods.FilterReferencedObjectIDs(scene, filteredReferences, m_Parameters.Target, m_Parameters.ScriptInfo, new HashSet <GUID>(m_Content.Assets)); sceneInfo.SetReferencedObjects(filteredReferences); } else { sceneInfo = ContentBuildInterface.CalculatePlayerDependenciesForScene(scenePath, settings, usageTags, m_DependencyData.DependencyUsageCache); } #else sceneInfo = ContentBuildInterface.CalculatePlayerDependenciesForScene(scenePath, settings, usageTags, m_DependencyData.DependencyUsageCache); #endif #else string outputFolder = m_Parameters.TempOutputFolder; if (m_Parameters.UseCache && m_Cache != null) { outputFolder = m_Cache.GetCachedArtifactsDirectory(m_Cache.GetCacheEntry(scene, Version)); } Directory.CreateDirectory(outputFolder); sceneInfo = ContentBuildInterface.PrepareScene(scenePath, settings, usageTags, m_DependencyData.DependencyUsageCache, outputFolder); #endif if (uncachedInfo != null) { // We only need to gather prefab dependencies and calculate the hash if we are using caching, otherwise we can skip it var prefabEntries = AssetDatabase.GetDependencies(AssetDatabase.GUIDToAssetPath(scene.ToString())).Where(path => path.EndsWith(".prefab")).Select(m_Cache.GetCacheEntry); prefabDependency = HashingMethods.Calculate(prefabEntries).ToHash128(); uncachedInfo.Add(GetCachedInfo(scene, sceneInfo.referencedObjects, sceneInfo, usageTags, prefabEntries, prefabDependency)); } } SetOutputInformation(scene, sceneInfo, usageTags, prefabDependency); } if (m_Parameters.UseCache && m_Cache != null) { m_Cache.SaveCachedData(uncachedInfo); } return(ReturnCode.Success); }