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; } } } } } } } }
private static void UpdateAddressablesBuild() { ExitCode code = ExitCode.UnknownError; BuildScript.buildCompleted += result => { if (!string.IsNullOrEmpty(result.Error)) { code = ExitCode.AddressablesBuildFailed; } else { code = ExitCode.Success; } }; // find out what version we are updating string statePath = "Artifacts/addressables_content_state.bin"; var state = ContentUpdateScript.LoadContentState(statePath); if (state != null) { Debug.Log("State file found, " + state.playerVersion); } code = state == null ? ExitCode.AddressablesContentFileNotFound : ExitCode.Success; List <AddressableAssetEntry> entries = ContentUpdateScript.GatherModifiedEntries(AddressableAssetSettingsDefaultObject.Settings, statePath); foreach (AddressableAssetEntry assetEntry in entries) { Debug.Log("Entry found to be moved - " + assetEntry.address); } Debug.Log("Creating update group"); ContentUpdateScript.CreateContentUpdateGroup(AddressableAssetSettingsDefaultObject.Settings, entries, "Update Group"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); ContentUpdateScript.BuildContentUpdate(AddressableAssetSettingsDefaultObject.Settings, statePath); // TODO edit catalog name. ExitOnError(code); }
public void CanCreateContentStateData() { var group = Settings.CreateGroup("LocalStuff", false, false, false, null); var schema = group.AddSchema <BundledAssetGroupSchema>(); schema.BuildPath.SetVariableByName(Settings, AddressableAssetSettings.kLocalBuildPath); schema.LoadPath.SetVariableByName(Settings, AddressableAssetSettings.kLocalLoadPath); schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogether; group.AddSchema <ContentUpdateGroupSchema>().StaticContent = true; Settings.CreateOrMoveEntry(m_AssetGUID, group); var context = new AddressablesDataBuilderInput(Settings); var op = Settings.ActivePlayerDataBuilder.BuildData <AddressablesPlayerBuildResult>(context); Assert.IsTrue(string.IsNullOrEmpty(op.Error), op.Error); var tempPath = Path.GetDirectoryName(Application.dataPath) + "/Library/com.unity.addressables/StreamingAssetsCopy/" + PlatformMappingService.GetPlatform() + "/addressables_content_state.bin"; var cacheData = ContentUpdateScript.LoadContentState(tempPath); Assert.NotNull(cacheData); }
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; } } } } }