public void IsCacheDataValid_WhenNoPreviousRemoteCatalogPath_ReturnsFalseWithError()
        {
            AddressablesContentState cacheData = new AddressablesContentState();

            cacheData.editorVersion = Application.unityVersion;
            Assert.IsFalse(ContentUpdateScript.IsCacheDataValid(Settings, cacheData));
            LogAssert.Expect(LogType.Error, new Regex("Previous build had 'Build Remote Catalog' disabled.*"));
        }
        public void IsCacheDataValid_WhenMismatchedEditorVersions_LogsWarning()
        {
            AddressablesContentState cacheData = new AddressablesContentState();

            cacheData.editorVersion = "invalid";
            Assert.IsFalse(ContentUpdateScript.IsCacheDataValid(Settings, cacheData));
            LogAssert.Expect(LogType.Warning, new Regex(".*with version `" + cacheData.editorVersion + "`.*"));
            LogAssert.Expect(LogType.Error, new Regex("Previous.*"));
        }
Example #3
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;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        public void IsCacheDataValid_WhenMismatchedCatalogPaths_ReturnsFalseWithError()
        {
            AddressablesContentState cacheData = new AddressablesContentState();

            cacheData.editorVersion         = Application.unityVersion;
            cacheData.remoteCatalogLoadPath = "somePath";
            var oldSetting = Settings.BuildRemoteCatalog;

            Settings.BuildRemoteCatalog = true;
            Assert.IsFalse(ContentUpdateScript.IsCacheDataValid(Settings, cacheData));
            LogAssert.Expect(LogType.Error, new Regex("Current 'Remote Catalog Load Path' does not match load path of original player.*"));
            Settings.BuildRemoteCatalog = oldSetting;
        }
        public void IsCacheDataValid_WhenRemoteCatalogDisabled_ReturnsFalseWithError()
        {
            AddressablesContentState cacheData = new AddressablesContentState();

            cacheData.editorVersion         = Application.unityVersion;
            cacheData.remoteCatalogLoadPath = "somePath";
            var oldSetting = Settings.BuildRemoteCatalog;

            Settings.BuildRemoteCatalog = false;
            Assert.IsFalse(ContentUpdateScript.IsCacheDataValid(Settings, cacheData));
            LogAssert.Expect(LogType.Error, new Regex("Current settings have 'Build Remote Catalog' disabled.*"));
            Settings.BuildRemoteCatalog = oldSetting;
        }
Example #6
0
        private static Dictionary <string, CachedAssetState> BuildGuidToCachedAssetStateMap(AddressablesContentState contentState, AddressableAssetSettings settings)
        {
            Dictionary <string, CachedAssetState> addressableEntryToCachedStateMap = new Dictionary <string, CachedAssetState>();

            foreach (var cachedInfo in contentState.cachedInfos)
            {
                addressableEntryToCachedStateMap[cachedInfo.asset.guid.ToString()] = cachedInfo;
            }

            return(addressableEntryToCachedStateMap);
        }
Example #7
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;
                        }
                    }
                }
            }
        }