public void AddPostCatalogUpdates_AddsCallbackToUpdateBundleLocation_WhenNamingSchemaIsSetToFilenameOnly() { //Setup AddressableAssetGroup group = Settings.CreateGroup("TestAddPostCatalogUpdate", false, false, false, new List <AddressableAssetGroupSchema>(), typeof(BundledAssetGroupSchema)); group.GetSchema <BundledAssetGroupSchema>().BundleNaming = BundledAssetGroupSchema.BundleNamingStyle.NoHash; List <Action> callbacks = new List <Action>(); string targetBundlePathHashed = "LocalPathToFile/testbundle_123456.bundle"; string targetBundlePathUnHashed = "LocalPathToFile/testbundle.bundle"; string targetBundleInternalIdHashed = "{runtime_val}/testbundle_123456.bundle"; string targetBundleInternalIdUnHashed = "{runtime_val}/testbundle.bundle"; ContentCatalogDataEntry dataEntry = new ContentCatalogDataEntry(typeof(ContentCatalogData), targetBundleInternalIdHashed, typeof(BundledAssetProvider).FullName, new List <object>()); FileRegistry registry = new FileRegistry(); registry.AddFile(targetBundlePathHashed); m_BuildScript.AddPostCatalogUpdatesInternal(group, callbacks, dataEntry, targetBundlePathHashed, registry); //Assert setup Assert.AreEqual(1, callbacks.Count); Assert.AreEqual(targetBundleInternalIdHashed, dataEntry.InternalId); //Test callbacks[0].Invoke(); //Assert Assert.AreEqual(targetBundleInternalIdUnHashed, dataEntry.InternalId); Assert.AreEqual(registry.GetFilePathForBundle("testbundle"), targetBundlePathUnHashed); //Cleanup Settings.RemoveGroup(group); }
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; } } } } } } } }