private static void ProcessCatalogEntriesForBuild(AddressableAssetsBuildContext aaContext, IBuildLogger log,
                                                          IEnumerable <AddressableAssetGroup> validGroups, AddressablesDataBuilderInput builderInput, IBundleWriteData writeData,
                                                          List <CachedAssetState> carryOverCachedState, Dictionary <string, string> bundleToInternalId)
        {
            using (log.ScopedStep(LogLevel.Info, "Catalog Entries."))
                using (var progressTracker = new UnityEditor.Build.Pipeline.Utilities.ProgressTracker())
                {
                    progressTracker.UpdateTask("Post Processing Catalog Entries");
                    Dictionary <string, ContentCatalogDataEntry> locationIdToCatalogEntryMap = BuildLocationIdToCatalogEntryMap(aaContext.locations);
                    if (builderInput.PreviousContentState != null)
                    {
                        ContentUpdateContext contentUpdateContext = new ContentUpdateContext()
                        {
                            BundleToInternalBundleIdMap = bundleToInternalId,
                            GuidToPreviousAssetStateMap = BuildGuidToCachedAssetStateMap(builderInput.PreviousContentState, aaContext.settings),
                            IdToCatalogDataEntryMap     = locationIdToCatalogEntryMap,
                            WriteData    = writeData,
                            ContentState = builderInput.PreviousContentState,
                            Registry     = builderInput.Registry,
                            PreviousAssetStateCarryOver = carryOverCachedState
                        };

                        RevertUnchangedAssetsToPreviousAssetState.Run(aaContext, contentUpdateContext);
                    }
                    else
                    {
                        foreach (var assetGroup in validGroups)
                        {
                            SetAssetEntriesBundleFileIdToCatalogEntryBundleFileId(assetGroup.entries, bundleToInternalId, writeData, locationIdToCatalogEntryMap);
                        }
                    }
                }

            bundleToInternalId.Clear();
        }
    internal static void ApplyAssetEntryUpdates(
        List <AssetEntryRevertOperation> operations,
        string bundleProviderName,
        List <ContentCatalogDataEntry> locations,
        ContentUpdateContext contentUpdateContext)
    {
        foreach (AssetEntryRevertOperation operation in operations)
        {
            //Check that we can replace the entry in the file registry
            //before continuing.  Past this point destructive actions are taken.
            if (contentUpdateContext.Registry.ReplaceBundleEntry(
                    Path.GetFileNameWithoutExtension(operation.PreviousBuildPath),
                    operation.PreviousAssetState.bundleFileId))
            {
                File.Delete(operation.CurrentBuildPath);
                operation.BundleCatalogEntry.InternalId = operation.PreviousAssetState.bundleFileId;
                if (contentUpdateContext.ContentState.cachedBundles != null)
                {
                    var bundleState = contentUpdateContext.ContentState.cachedBundles.FirstOrDefault(s => s.bundleFileId == operation.PreviousAssetState.bundleFileId);
                    operation.BundleCatalogEntry.Data = bundleState != null ? bundleState.data : null;
                }
                //If the entry has dependencies, we need to update those to point to their respective cached versions as well.
                if (operation.PreviousAssetState.dependencies.Length > 0)
                {
                    operation.BundleCatalogEntry.Dependencies.Clear();
                    foreach (AssetState state in operation.PreviousAssetState.dependencies)
                    {
                        if (contentUpdateContext.GuidToPreviousAssetStateMap.TryGetValue(state.guid.ToString(), out var cachedDependencyState) &&
                            !string.IsNullOrEmpty(cachedDependencyState.bundleFileId))
                        {
                            string modifiedKey = cachedDependencyState.bundleFileId + operation.AssetEntry.GetHashCode();
                            locations.Add(new ContentCatalogDataEntry(
                                              typeof(IAssetBundleResource),
                                              cachedDependencyState.bundleFileId,
                                              bundleProviderName,
                                              new List <object>()
                            {
                                modifiedKey
                            }));

                            contentUpdateContext.Registry.AddFile(cachedDependencyState.bundleFileId);
                            if (!operation.BundleCatalogEntry.Dependencies.Contains(modifiedKey))
                            {
                                operation.BundleCatalogEntry.Dependencies.Add(modifiedKey);
                            }

                            contentUpdateContext.PreviousAssetStateCarryOver.Add(cachedDependencyState);
                        }
                    }
                }
                //sync the internal ids of the catalog entry and asset entry to the cached state
                operation.BundleCatalogEntry.InternalId = operation.AssetEntry.BundleFileId = operation.PreviousAssetState.bundleFileId;
            }
        }
    }
Exemple #3
0
 private static bool IsPreviouslyRevertedDependency(string bundleFileId, ContentUpdateContext contentUpdateContext)
 {
     foreach (CachedAssetState state in contentUpdateContext.PreviousAssetStateCarryOver)
     {
         if (state.bundleFileId == bundleFileId)
         {
             return(true);
         }
     }
     return(false);
 }
    internal static ReturnCode Run(IAddressableAssetsBuildContext aaBuildContext, ContentUpdateContext updateContext)
    {
        var aaContext = aaBuildContext as AddressableAssetsBuildContext;
        var groups    = aaContext.settings.groups.Where(group => group != null && group.HasSchema <BundledAssetGroupSchema>());

        foreach (var assetGroup in groups)
        {
            List <AssetEntryRevertOperation> operations = DetermineRequiredAssetEntryUpdates(assetGroup, updateContext);
            ApplyAssetEntryUpdates(operations, GenerateLocationListsTask.GetBundleProviderName(assetGroup), aaContext.locations, updateContext);
        }

        return(ReturnCode.Success);
    }
    internal static ReturnCode Run(IAddressableAssetsBuildContext aaBuildContext, ContentUpdateContext updateContext)
    {
        var aaContext = aaBuildContext as AddressableAssetsBuildContext;
        var groups    = aaContext.Settings.groups.Where(group => group != null && group.HasSchema <BundledAssetGroupSchema>());

        if (updateContext.ContentState.cachedBundles == null)
        {
            UnityEngine.Debug.LogWarning($"ContentUpdateContext does not contain previous asset bundle info, remote static bundles that are updated will not be cacheable.  If this is needed, rebuild the shipped application state with the current version of addressables to update the addressables_content_state.bin file.  The updated addressables_content_state.bin file can be used to create the content update.");
        }

        foreach (var assetGroup in groups)
        {
            List <AssetEntryRevertOperation> operations = DetermineRequiredAssetEntryUpdates(assetGroup, updateContext);
            ApplyAssetEntryUpdates(operations, GenerateLocationListsTask.GetBundleProviderName(assetGroup), aaContext.locations, updateContext);
        }

        return(ReturnCode.Success);
    }