Exemplo n.º 1
0
        /// <summary>
        /// Save the content update information for a set of AddressableAssetEntry objects.
        /// </summary>
        /// <param name="locations">The ContentCatalogDataEntry locations that were built into the Content Catalog.</param>
        /// <param name="path">File to write content stat info to.  If file already exists, it will be deleted before the new file is created.</param>
        /// <param name="entries">The entries to save.</param>
        /// <param name="dependencyData">The raw dependency information generated from the build.</param>
        /// <param name="playerVersion">The player version to save. This is usually set to AddressableAssetSettings.PlayerBuildVersion.</param>
        /// <param name="remoteCatalogPath">The server path (if any) that contains an updateable content catalog.  If this is empty, updates cannot occur.</param>
        /// <param name="carryOverCacheState">Cached state that needs to carry over from the previous build.  This mainly affects Content Update.</param>
        /// <returns>True if the file is saved, false otherwise.</returns>
        public static bool SaveContentState(List <ContentCatalogDataEntry> locations, string path, List <AddressableAssetEntry> entries, IDependencyData dependencyData, string playerVersion, string remoteCatalogPath, List <CachedAssetState> carryOverCacheState)
        {
            try
            {
                Dictionary <string, AddressableAssetEntry>   guidToEntries   = new Dictionary <string, AddressableAssetEntry>();
                Dictionary <string, ContentCatalogDataEntry> key1ToCCEntries = new Dictionary <string, ContentCatalogDataEntry>();

                foreach (AddressableAssetEntry entry in entries)
                {
                    if (!guidToEntries.ContainsKey(entry.guid))
                    {
                        guidToEntries[entry.guid] = entry;
                    }
                }
                foreach (ContentCatalogDataEntry ccEntry in locations)
                {
                    if (ccEntry != null && ccEntry.Keys != null && ccEntry.Keys.Count > 1 && (ccEntry.Keys[1] as string) != null && !key1ToCCEntries.ContainsKey(ccEntry.Keys[1] as string))
                    {
                        key1ToCCEntries[ccEntry.Keys[1] as string] = ccEntry;
                    }
                }

                var cachedBundleInfos = new List <CachedBundleState>();
                foreach (ContentCatalogDataEntry ccEntry in locations)
                {
                    if (typeof(IAssetBundleResource).IsAssignableFrom(ccEntry.ResourceType))
                    {
                        cachedBundleInfos.Add(new CachedBundleState()
                        {
                            bundleFileId = ccEntry.InternalId, data = ccEntry.Data
                        });
                    }
                }


                IList <CachedAssetState> cachedInfos = new List <CachedAssetState>();
                foreach (var assetData in dependencyData.AssetInfo)
                {
                    guidToEntries.TryGetValue(assetData.Key.ToString(), out AddressableAssetEntry addressableAssetEntry);
                    key1ToCCEntries.TryGetValue(assetData.Key.ToString(), out ContentCatalogDataEntry catalogAssetEntry);
                    if (addressableAssetEntry != null && catalogAssetEntry != null &&
                        GetCachedAssetStateForData(assetData.Key, addressableAssetEntry.BundleFileId, addressableAssetEntry.parentGroup.Guid, catalogAssetEntry.Data, assetData.Value.referencedObjects.Select(x => x.guid), out CachedAssetState cachedAssetState))
                    {
                        cachedInfos.Add(cachedAssetState);
                    }
                }

                foreach (var sceneData in dependencyData.SceneInfo)
                {
                    guidToEntries.TryGetValue(sceneData.Key.ToString(), out AddressableAssetEntry addressableSceneEntry);
                    key1ToCCEntries.TryGetValue(sceneData.Key.ToString(), out ContentCatalogDataEntry catalogSceneEntry);
                    if (addressableSceneEntry != null && catalogSceneEntry != null &&
                        GetCachedAssetStateForData(sceneData.Key, addressableSceneEntry.BundleFileId, addressableSceneEntry.parentGroup.Guid, catalogSceneEntry.Data, sceneData.Value.referencedObjects.Select(x => x.guid), out CachedAssetState cachedAssetState))
                    {
                        cachedInfos.Add(cachedAssetState);
                    }
                }

                if (carryOverCacheState != null)
                {
                    foreach (var cs in carryOverCacheState)
                    {
                        cachedInfos.Add(cs);
                    }
                }

                var cacheData = new AddressablesContentState
                {
                    cachedInfos           = cachedInfos.ToArray(),
                    playerVersion         = playerVersion,
                    editorVersion         = Application.unityVersion,
                    remoteCatalogLoadPath = remoteCatalogPath,
                    cachedBundles         = cachedBundleInfos.ToArray()
                };
                var formatter = new BinaryFormatter();
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                var dir = Path.GetDirectoryName(path);
                if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                var stream = new FileStream(path, FileMode.CreateNew, FileAccess.Write);
                formatter.Serialize(stream, cacheData);
                stream.Flush();
                stream.Close();
                stream.Dispose();
                return(true);
            }
            catch (UnauthorizedAccessException uae)
            {
                if (AddressableAssetUtility.IsUsingVCIntegration())
                {
                    Debug.LogErrorFormat("Cannot access the file {0}. Is it checked out?", path);
                }
                else
                {
                    Debug.LogException(uae);
                }
                return(false);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Save the content update information for a set of AddressableAssetEntry objects.
        /// </summary>
        /// <param name="locations">The ContentCatalogDataEntry locations that were built into the Content Catalog.</param>
        /// <param name="path">File to write content stat info to.  If file already exists, it will be deleted before the new file is created.</param>
        /// <param name="entries">The entries to save.</param>
        /// <param name="dependencyData">The raw dependency information generated from the build.</param>
        /// <param name="playerVersion">The player version to save. This is usually set to AddressableAssetSettings.PlayerBuildVersion.</param>
        /// <param name="remoteCatalogPath">The server path (if any) that contains an updateable content catalog.  If this is empty, updates cannot occur.</param>
        /// <param name="carryOverCacheState">Cached state that needs to carry over from the previous build.  This mainly affects Content Update.</param>
        /// <returns>True if the file is saved, false otherwise.</returns>
        public static bool SaveContentState(List <ContentCatalogDataEntry> locations, string path, List <AddressableAssetEntry> entries, IDependencyData dependencyData, string playerVersion, string remoteCatalogPath, List <CachedAssetState> carryOverCacheState)
        {
            try
            {
                var cachedInfos = GetCachedAssetStates(locations, entries, dependencyData);

                var cachedBundleInfos = new List <CachedBundleState>();
                foreach (ContentCatalogDataEntry ccEntry in locations)
                {
                    if (typeof(IAssetBundleResource).IsAssignableFrom(ccEntry.ResourceType))
                    {
                        cachedBundleInfos.Add(new CachedBundleState()
                        {
                            bundleFileId = ccEntry.InternalId, data = ccEntry.Data
                        });
                    }
                }

                if (carryOverCacheState != null)
                {
                    foreach (var cs in carryOverCacheState)
                    {
                        cachedInfos.Add(cs);
                    }
                }

                var cacheData = new AddressablesContentState
                {
                    cachedInfos           = cachedInfos.ToArray(),
                    playerVersion         = playerVersion,
                    editorVersion         = Application.unityVersion,
                    remoteCatalogLoadPath = remoteCatalogPath,
                    cachedBundles         = cachedBundleInfos.ToArray()
                };
                var formatter = new BinaryFormatter();
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                var dir = Path.GetDirectoryName(path);
                if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                var stream = new FileStream(path, FileMode.CreateNew, FileAccess.Write);
                formatter.Serialize(stream, cacheData);
                stream.Flush();
                stream.Close();
                stream.Dispose();
                return(true);
            }
            catch (UnauthorizedAccessException uae)
            {
                if (AddressableAssetUtility.IsUsingVCIntegration())
                {
                    Debug.LogErrorFormat("Cannot access the file {0}. Is it checked out?", path);
                }
                else
                {
                    Debug.LogException(uae);
                }
                return(false);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                return(false);
            }
        }
Exemplo n.º 3
0
        public static bool SaveContentState(string path, List <AddressableAssetEntry> entries, IDependencyData dependencyData, string playerVersion, string remoteCatalogPath)
        {
            try
            {
                IList <CachedAssetState> cachedInfos = new List <CachedAssetState>();
                foreach (var assetData in dependencyData.AssetInfo)
                {
                    CachedAssetState cachedAssetState;
                    if (GetCachedAssetStateForData(assetData.Key, null, null, null, assetData.Value.referencedObjects.Select(x => x.guid), out cachedAssetState))
                    {
                        cachedInfos.Add(cachedAssetState);
                    }
                }
                foreach (var sceneData in dependencyData.SceneInfo)
                {
                    CachedAssetState cachedAssetState;
                    if (GetCachedAssetStateForData(sceneData.Key, null, null, null, sceneData.Value.referencedObjects.Select(x => x.guid), out cachedAssetState))
                    {
                        cachedInfos.Add(cachedAssetState);
                    }
                }

                var cacheData = new AddressablesContentState
                {
                    cachedInfos           = cachedInfos.ToArray(),
                    playerVersion         = playerVersion,
                    editorVersion         = Application.unityVersion,
                    remoteCatalogLoadPath = remoteCatalogPath
                };
                var formatter = new BinaryFormatter();
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                var dir = Path.GetDirectoryName(path);
                if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                var stream = new FileStream(path, FileMode.CreateNew, FileAccess.Write);
                formatter.Serialize(stream, cacheData);
                stream.Flush();
                stream.Close();
                stream.Dispose();
                return(true);
            }
            catch (UnauthorizedAccessException uae)
            {
                if (AddressableAssetUtility.IsUsingVCIntegration())
                {
                    Debug.LogErrorFormat("Cannot access the file {0}. This may be due to a version control lock.", path);
                }
                else
                {
                    Debug.LogException(uae);
                }
                return(false);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                return(false);
            }
        }