public static ReturnCode Run(IAddressableAssetsBuildContext aaBuildContext, IBundleWriteData writeData)
        {
            var task = new GenerateLocationListsTask();

            task.m_AaBuildContext = aaBuildContext;
            task.m_WriteData      = writeData;
            return(task.Run());
        }
Exemple #2
0
        private void PostProcessCatalogEnteries(AddressableAssetGroup group, IBundleWriteData writeData, List <ContentCatalogDataEntry> locations, FileRegistry fileRegistry)
        {
            if (!group.HasSchema <BundledAssetGroupSchema>() || !File.Exists(ContentUpdateScript.GetContentStateDataPath(false)))
            {
                return;
            }

            AddressablesContentState contentState = ContentUpdateScript.LoadContentState(ContentUpdateScript.GetContentStateDataPath(false));

            foreach (AddressableAssetEntry entry in group.entries)
            {
                CachedAssetState cachedAsset = contentState.cachedInfos.FirstOrDefault(i => i.asset.guid.ToString() == entry.guid);
                if (cachedAsset != null)
                {
                    if (entry.parentGroup.Guid == cachedAsset.groupGuid)
                    {
                        GUID guid = new GUID(entry.guid);
                        if (!writeData.AssetToFiles.ContainsKey(guid))
                        {
                            continue;
                        }

                        string file           = writeData.AssetToFiles[guid][0];
                        string fullBundleName = writeData.FileToBundle[file];

                        ContentCatalogDataEntry catalogBundleEntry = locations.FirstOrDefault((loc) => (loc.Keys[0] as string) == fullBundleName);

                        if (catalogBundleEntry != null)
                        {
                            if (String.IsNullOrEmpty(entry.BundleFileId))
                            {
                                entry.BundleFileId = catalogBundleEntry.InternalId;
                            }
                            else
                            {
                                if (catalogBundleEntry.InternalId != cachedAsset.bundleFileId)
                                {
                                    string unusedBundlePath =
                                        fileRegistry.GetFilePathForBundle(
                                            Path.GetFileNameWithoutExtension(fullBundleName));

                                    if (File.Exists(unusedBundlePath) &&
                                        fileRegistry.ReplaceBundleEntry(
                                            Path.GetFileNameWithoutExtension(fullBundleName),
                                            cachedAsset.bundleFileId))
                                    {
                                        File.Delete(unusedBundlePath);
                                        catalogBundleEntry.InternalId = entry.BundleFileId;
                                        catalogBundleEntry.Data       = cachedAsset.data;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        internal static void SetAssetEntriesBundleFileIdToCatalogEntryBundleFileId(ICollection <AddressableAssetEntry> assetEntries, Dictionary <string, string> bundleNameToInternalBundleIdMap,
                                                                                   IBundleWriteData writeData, Dictionary <string, ContentCatalogDataEntry> locationIdToCatalogEntryMap)
        {
            foreach (var loc in assetEntries)
            {
                GUID guid = new GUID(loc.guid);
                //For every entry in the write data we need to ensure the BundleFileId is set so we can save it correctly in the cached state
                if (writeData.AssetToFiles.TryGetValue(guid, out List <string> files))
                {
                    string file              = files[0];
                    string fullBundleName    = writeData.FileToBundle[file];
                    string convertedLocation = bundleNameToInternalBundleIdMap[fullBundleName];

                    if (locationIdToCatalogEntryMap.TryGetValue(convertedLocation, out ContentCatalogDataEntry catalogEntry))
                    {
                        loc.BundleFileId = catalogEntry.InternalId;
                    }
                }
            }
        }
        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 ReturnCode RunInternal(IAddressableAssetsBuildContext aaBuildContext, IBundleWriteData writeData, IDependencyData dependencyData)
        {
            var aaContext = aaBuildContext as AddressableAssetsBuildContext;

            if (aaContext == null)
            {
                return(ReturnCode.Error);
            }
            AddressableAssetSettings       aaSettings         = aaContext.Settings;
            List <ContentCatalogDataEntry> locations          = aaContext.locations;
            Dictionary <string, string>    bundleToAssetGroup = aaContext.bundleToAssetGroup;
            var bundleToAssets         = new Dictionary <string, List <GUID> >();
            var dependencySetForBundle = new Dictionary <string, HashSet <string> >();

            foreach (KeyValuePair <GUID, List <string> > k in writeData.AssetToFiles)
            {
                List <GUID> assetList;
                string      bundle = writeData.FileToBundle[k.Value[0]];
                if (!bundleToAssets.TryGetValue(bundle, out assetList))
                {
                    bundleToAssets.Add(bundle, assetList = new List <GUID>());
                }
                HashSet <string> bundleDeps;
                if (!dependencySetForBundle.TryGetValue(bundle, out bundleDeps))
                {
                    dependencySetForBundle.Add(bundle, bundleDeps = new HashSet <string>());
                }
                for (int i = 0; i < k.Value.Count; i++)
                {
                    bundleDeps.Add(writeData.FileToBundle[k.Value[i]]);
                }
                foreach (string file in k.Value)
                {
                    string fileBundle = writeData.FileToBundle[file];
                    if (!bundleToAssets.ContainsKey(fileBundle))
                    {
                        bundleToAssets.Add(fileBundle, new List <GUID>());
                    }
                }

                assetList.Add(k.Key);
            }
            var assetGroupToBundle = (aaContext.assetGroupToBundles = new Dictionary <AddressableAssetGroup, List <string> >());

            foreach (KeyValuePair <string, List <GUID> > kvp in bundleToAssets)
            {
                AddressableAssetGroup assetGroup = aaSettings.DefaultGroup;
                string groupGuid;
                if (bundleToAssetGroup.TryGetValue(kvp.Key, out groupGuid))
                {
                    assetGroup = aaSettings.FindGroup(g => g != null && g.Guid == groupGuid);
                }

                List <string> bundles;
                if (!assetGroupToBundle.TryGetValue(assetGroup, out bundles))
                {
                    assetGroupToBundle.Add(assetGroup, bundles = new List <string>());
                }
                bundles.Add(kvp.Key);
                HashSet <string> bundleDeps = null;
                dependencySetForBundle.TryGetValue(kvp.Key, out bundleDeps);
                CreateResourceLocationData(assetGroup, kvp.Key, GetLoadPath(assetGroup, kvp.Key), GetBundleProviderName(assetGroup), GetAssetProviderName(assetGroup), kvp.Value, bundleDeps, locations, aaContext.providerTypes, dependencyData);
            }

            return(ReturnCode.Success);
        }
 public static ReturnCode Run(IAddressableAssetsBuildContext aaBuildContext, IBundleWriteData writeData)
 {
     return(RunInternal(aaBuildContext, writeData, null));
 }
Exemple #7
0
        public static ReturnCode Run(IAddressableAssetsBuildContext aaBuildContext, IBundleWriteData writeData)
        {
            var aaContext = aaBuildContext as AddressableAssetsBuildContext;

            if (aaContext == null)
            {
                return(ReturnCode.Error);
            }
            var aaSettings         = aaContext.settings;
            var locations          = aaContext.locations;
            var bundleToAssetGroup = aaContext.bundleToAssetGroup;
            var bundleToAssets     = new Dictionary <string, List <GUID> >();
            var assetsToBundles    = new Dictionary <GUID, List <string> >();

            foreach (var k in writeData.AssetToFiles)
            {
                List <string> bundleList = new List <string>();
                assetsToBundles.Add(k.Key, bundleList);
                List <GUID> assetList;
                var         bundle = writeData.FileToBundle[k.Value[0]];
                if (!bundleToAssets.TryGetValue(bundle, out assetList))
                {
                    bundleToAssets.Add(bundle, assetList = new List <GUID>());
                }
                if (!bundleList.Contains(bundle))
                {
                    bundleList.Add(bundle);
                }
                foreach (var file in k.Value)
                {
                    var fileBundle = writeData.FileToBundle[file];
                    if (!bundleList.Contains(fileBundle))
                    {
                        bundleList.Add(fileBundle);
                    }
                    if (!bundleToAssets.ContainsKey(fileBundle))
                    {
                        bundleToAssets.Add(fileBundle, new List <GUID>());
                    }
                }

                assetList.Add(k.Key);
            }
            var assetGroupToBundle = (aaContext.assetGroupToBundles = new Dictionary <AddressableAssetGroup, List <string> >());

            foreach (var kvp in bundleToAssets)
            {
                AddressableAssetGroup assetGroup = aaSettings.DefaultGroup;
                string groupGuid;
                if (bundleToAssetGroup.TryGetValue(kvp.Key, out groupGuid))
                {
                    assetGroup = aaSettings.FindGroup(g => g.Guid == groupGuid);
                }

                List <string> bundles;
                if (!assetGroupToBundle.TryGetValue(assetGroup, out bundles))
                {
                    assetGroupToBundle.Add(assetGroup, bundles = new List <string>());
                }
                bundles.Add(kvp.Key);
                CreateResourceLocationData(assetGroup, kvp.Key, GetLoadPath(assetGroup, kvp.Key), GetBundleProviderName(assetGroup), GetAssetProviderName(assetGroup), kvp.Value, assetsToBundles, locations);
            }

            return(ReturnCode.Success);
        }
Exemple #8
0
        private void PostProcessCatalogEnteries(AddressableAssetGroup group, IBundleWriteData writeData, List <ContentCatalogDataEntry> locations, FileRegistry fileRegistry)
        {
            if (!group.HasSchema <BundledAssetGroupSchema>() ||
                !File.Exists(ContentUpdateScript.GetContentStateDataPath(false)))
            {
                return;
            }

            AddressablesContentState contentState =
                ContentUpdateScript.LoadContentState(ContentUpdateScript.GetContentStateDataPath(false));

            foreach (AddressableAssetEntry entry in group.entries)
            {
                CachedAssetState cachedAsset =
                    contentState.cachedInfos.FirstOrDefault(i => i.asset.guid.ToString() == entry.guid);
                if (cachedAsset != null)
                {
                    GUID guid = new GUID(entry.guid);
                    if (!writeData.AssetToFiles.ContainsKey(guid))
                    {
                        continue;
                    }

                    string file              = writeData.AssetToFiles[guid][0];
                    string fullBundleName    = writeData.FileToBundle[file];
                    string convertedLocation = m_BundleToInternalId[fullBundleName];

                    ContentCatalogDataEntry catalogBundleEntry = locations.FirstOrDefault((loc) => loc.InternalId == (convertedLocation));

                    if (catalogBundleEntry != null)
                    {
                        if (entry.parentGroup.Guid == cachedAsset.groupGuid)
                        {
                            //Asset hash hasn't changed
                            if (AssetDatabase.GetAssetDependencyHash(entry.AssetPath) == cachedAsset.asset.hash)
                            {
                                if (catalogBundleEntry.InternalId != cachedAsset.bundleFileId)
                                {
                                    string builtBundlePath = m_BundleToInternalId[fullBundleName].Replace(
                                        group.GetSchema <BundledAssetGroupSchema>().LoadPath.GetValue(group.Settings),
                                        group.GetSchema <BundledAssetGroupSchema>().BuildPath.GetValue(group.Settings));

                                    string cachedBundlePath = cachedAsset.bundleFileId?.Replace(
                                        group.GetSchema <BundledAssetGroupSchema>().LoadPath.GetValue(group.Settings),
                                        group.GetSchema <BundledAssetGroupSchema>().BuildPath.GetValue(group.Settings));

                                    //Need to check and make sure our cached version exists
                                    if (!string.IsNullOrEmpty(cachedBundlePath) && File.Exists(cachedBundlePath))
                                    {
                                        //Try and replace the new bundle entry with the cached one and delete the new bundle
                                        if (File.Exists(builtBundlePath) &&
                                            fileRegistry.ReplaceBundleEntry(
                                                Path.GetFileNameWithoutExtension(convertedLocation),
                                                cachedAsset.bundleFileId))
                                        {
                                            File.Delete(builtBundlePath);
                                            catalogBundleEntry.InternalId = cachedAsset.bundleFileId;
                                            catalogBundleEntry.Data       = cachedAsset.data;
                                            entry.BundleFileId            = cachedAsset.bundleFileId;
                                        }
                                    }
                                }
                            }
                            entry.BundleFileId       = catalogBundleEntry.InternalId;
                            cachedAsset.bundleFileId = catalogBundleEntry.InternalId;
                        }
                    }
                }
            }
        }