Пример #1
0
        private void DownloadAssetFileCallback(Message <AssetFileDownloadResult> msg)
        {
            if (msg.IsError)
            {
                Debug.LogError(msg.GetError().Message, this);
                return;
            }

            AssetFileDownloadResult result = msg.GetAssetFileDownloadResult();

            Debug.Log("Asset file downloaded to: " + result.Filepath);

            // Parse Addressable key
            string[] temp = result.Filepath.Split('\\');
            string   key  = temp[temp.Length - 1];

            // Add filepath and parsed key to the Addressable resource locators
            List <ResourceLocationData> locationData = new List <ResourceLocationData>();

            locationData.Add(new ResourceLocationData(
                                 new string[] { key }, result.Filepath, typeof(AssetBundleProvider), typeof(AssetBundle)));
            ResourceLocationMap locMap = new ResourceLocationMap(result.Filepath, locationData);

            Addressables.AddResourceLocator(locMap);

            // if (new AssetReference(AssetDatabase.AssetPathToGUID(newPath)).RuntimeKeyIsValid())
            //     Debug.Log("F*****G AYYYYYYY MATE");
            // else
            //     Debug.LogError("Invalid AssetReference", this);

            PopulateAssetList();
        }
Пример #2
0
        protected override void Execute()
        {
            Addressables.LogFormat("Addressables - runtime data operation completed with status = {0}, result = {1}.", m_rtdOp.Status, m_rtdOp.Result);
            if (m_rtdOp.Result == null)
            {
                Addressables.LogWarningFormat("Addressables - Unable to load runtime data at location {0}.", m_rtdOp);
                Complete(Result, false, string.Format("Addressables - Unable to load runtime data at location {0}.", m_rtdOp));
                return;
            }
            var rtd = m_rtdOp.Result;

            m_Addressables.Release(m_rtdOp);
            if (rtd.CertificateHandlerType != null)
            {
                m_Addressables.ResourceManager.CertificateHandlerInstance = Activator.CreateInstance(rtd.CertificateHandlerType) as CertificateHandler;
            }

#if UNITY_EDITOR
            if (UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString() != rtd.BuildTarget)
            {
                Addressables.LogErrorFormat("Addressables - runtime data was built with a different build target.  Expected {0}, but data was built with {1}.  Certain assets may not load correctly including shaders.  You can rebuild player content via the Addressables window.", UnityEditor.EditorUserBuildSettings.activeBuildTarget, rtd.BuildTarget);
            }
#endif
            if (!rtd.LogResourceManagerExceptions)
            {
                ResourceManager.ExceptionHandler = null;
            }

            if (!rtd.ProfileEvents)
            {
                m_Diagnostics.Dispose();
                m_Diagnostics = null;
            }

            //   DiagnosticEventCollector.ResourceManagerProfilerEventsEnabled = rtd.ProfileEvents;
            Addressables.Log("Addressables - loading initialization objects.");

            ContentCatalogProvider ccp = m_Addressables.ResourceManager.ResourceProviders
                                         .FirstOrDefault(rp => rp.GetType() == typeof(ContentCatalogProvider)) as ContentCatalogProvider;
            if (ccp != null)
            {
                ccp.DisableCatalogUpdateOnStart = rtd.DisableCatalogUpdateOnStartup;
            }

            var locMap = new ResourceLocationMap("CatalogLocator", rtd.CatalogLocations);
            m_Addressables.AddResourceLocator(locMap);
            IList <IResourceLocation> catalogs;
            if (!locMap.Locate(ResourceManagerRuntimeData.kCatalogAddress, typeof(ContentCatalogData), out catalogs))
            {
                Addressables.LogWarningFormat(
                    "Addressables - Unable to find any catalog locations in the runtime data.");
                m_Addressables.RemoveResourceLocator(locMap);
                Complete(Result, false, "Addressables - Unable to find any catalog locations in the runtime data.");
            }
            else
            {
                Addressables.LogFormat("Addressables - loading content catalogs, {0} found.", catalogs.Count);
                LoadContentCatalogInternal(catalogs, 0, locMap);
            }
        }
Пример #3
0
        public void CreateCustomLocator_RetrunsLocatorWithUniqueId()
        {
            ContentCatalogData ccd = new ContentCatalogData();

            ccd.SetData(new List <ContentCatalogDataEntry>());
            ResourceLocationMap map = ccd.CreateCustomLocator("test");

            Assert.AreEqual("test", map.LocatorId);
        }
        public IEnumerator GetDownloadSize_CalculatesCachedBundles()
        {
#if ENABLE_CACHING
            yield return(Init());

            long expectedSize = 0;
            long bundleSize1  = 1000;
            long bundleSize2  = 500;
            var  locMap       = new ResourceLocationMap("TestLocator");

            Caching.ClearCache();
            //Simulating a cached bundle
            string fakeCachePath = CreateFakeCachedBundle("GetDownloadSize_CalculatesCachedBundlesBundle1", "be38e35d2177c282d5d6a2e54a803aab");

            var bundleLoc1 = new ResourceLocationBase("sizeTestBundle1", "http://nowhere.com/GetDownloadSize_CalculatesCachedBundlesBundle1.bundle",
                                                      typeof(AssetBundleProvider).FullName, typeof(object));
            var sizeData1 =
                (bundleLoc1.Data = CreateLocationSizeData("cachedSizeTestBundle1", bundleSize1, 123,
                                                          "be38e35d2177c282d5d6a2e54a803aab")) as ILocationSizeData;
            if (sizeData1 != null)
            {
                expectedSize += sizeData1.ComputeSize(bundleLoc1);
            }

            var bundleLoc2 = new ResourceLocationBase("cachedSizeTestBundle2", "http://nowhere.com/GetDownloadSize_CalculatesCachedBundlesBundle2.bundle",
                                                      typeof(AssetBundleProvider).FullName, typeof(object));
            var sizeData2 =
                (bundleLoc2.Data = CreateLocationSizeData("cachedSizeTestBundle2", bundleSize2, 123,
                                                          "d9fe965a6b253fb9dbd3e1cb08b7d66f")) as ILocationSizeData;
            if (sizeData2 != null)
            {
                expectedSize += sizeData2.ComputeSize(bundleLoc2);
            }

            var assetLoc = new ResourceLocationBase("cachedSizeTestAsset", "myASset.asset",
                                                    typeof(BundledAssetProvider).FullName, typeof(object), bundleLoc1, bundleLoc2);

            locMap.Add("cachedSizeTestBundle1", bundleLoc1);
            locMap.Add("cachedSizeTestBundle2", bundleLoc2);
            locMap.Add("cachedSizeTestAsset", assetLoc);
            m_Addressables.AddResourceLocator(locMap);

            var dOp = m_Addressables.GetDownloadSizeAsync("cachedSizeTestAsset");
            yield return(dOp);

            Assert.IsTrue((bundleSize1 + bundleSize2) > dOp.Result);
            Assert.AreEqual(expectedSize, dOp.Result);

            dOp.Release();
            m_Addressables.RemoveResourceLocator(locMap);
            Directory.Delete(fakeCachePath, true);
#else
            Assert.Ignore();
            yield break;
#endif
        }
Пример #5
0
    private void Cloud_Completed(AsyncOperationHandle <IResourceLocator> obj)
    {
        Addressables.AddResourceLocator(obj.Result);
        Debug.LogError(obj.Result);
        Debug.LogError(obj.Result.Keys);
        Debug.LogError(obj.Result.LocatorId);
        map = (ResourceLocationMap)obj.Result;

        contentCatalogLoaded = true;
    }
Пример #6
0
        //================================================================================
        // 関数(static)
        //================================================================================
        /// <summary>
        /// すべての IAssetBundleResource を返します
        /// </summary>
        public static IEnumerable <IResourceLocation> GetAllAssetBundleLocation
        (
            this ResourceLocationMap self
        )
        {
            var resourceType = typeof(IAssetBundleResource);

            return(self.Locations.Values
                   .SelectMany(x => x)
                   .Where(x => x.ResourceType == resourceType)
                   .GroupBy(x => x.PrimaryKey)
                   .Select(x => x.FirstOrDefault())
                   );
        }
        static AsyncOperationHandle <IResourceLocator> OnCatalogDataLoaded(AddressablesImpl addressables, AsyncOperationHandle <ContentCatalogData> op, string providerSuffix, IResourceLocation remoteHashLocation)
        {
            var data = op.Result;

            addressables.Release(op);
            if (data == null)
            {
                var opException = op.OperationException != null ? new Exception("Failed to load content catalog.", op.OperationException) : new Exception("Failed to load content catalog.");
                return(addressables.ResourceManager.CreateCompletedOperationWithException <IResourceLocator>(null, opException));
            }
            else
            {
                if (data.ResourceProviderData != null)
                {
                    foreach (var providerData in data.ResourceProviderData)
                    {
                        LoadProvider(addressables, providerData, providerSuffix);
                    }
                }
                if (addressables.InstanceProvider == null)
                {
                    var prov = data.InstanceProviderData.CreateInstance <IInstanceProvider>();
                    if (prov != null)
                    {
                        addressables.InstanceProvider = prov;
                    }
                }
                if (addressables.SceneProvider == null)
                {
                    var prov = data.SceneProviderData.CreateInstance <ISceneProvider>();
                    if (prov != null)
                    {
                        addressables.SceneProvider = prov;
                    }
                }
                if (remoteHashLocation != null)
                {
                    data.location.Dependencies[(int)ContentCatalogProvider.DependencyHashIndex.Remote] = remoteHashLocation;
                }

                ResourceLocationMap locMap = data.CreateCustomLocator(data.location.PrimaryKey, providerSuffix);
                addressables.AddResourceLocator(locMap, data.localHash, data.location);
                addressables.AddResourceLocator(new DynamicResourceLocator(addressables));
                return(addressables.ResourceManager.CreateCompletedOperation <IResourceLocator>(locMap, string.Empty));
            }
        }
Пример #8
0
        /// <summary>
        /// 解析ResourceLocationMap 中所有的bundle
        /// </summary>
        /// <param name="locMap"></param>
        /// <returns></returns>
        static Dictionary <string, IResourceLocation> parseBundleList(ResourceLocationMap locMap, string flag)
        {
            Dictionary <string, IResourceLocation> bundleMap = new Dictionary <string, IResourceLocation>();

            foreach (var key in locMap.Keys)
            {
                IList <IResourceLocation> locations;
                locMap.Locations.TryGetValue(key, out locations);
                foreach (var _location in locations)
                {
                    if (_location.ResourceType == typeof(IAssetBundleResource) && !bundleMap.ContainsKey(_location.PrimaryKey))
                    {
                        bundleMap.Add(_location.PrimaryKey, _location);
                    }
                }
            }
            return(bundleMap);
        }
        static AsyncOperationHandle <IResourceLocator> OnCatalogDataLoaded(AddressablesImpl addressables, AsyncOperationHandle <ContentCatalogData> op, string providerSuffix)
        {
            var data = op.Result;

            addressables.Release(op);
            if (data == null)
            {
                return(addressables.ResourceManager.CreateCompletedOperation <IResourceLocator>(null, new Exception("Failed to load content catalog.").Message));
            }
            else
            {
                if (data.ResourceProviderData != null)
                {
                    foreach (var providerData in data.ResourceProviderData)
                    {
                        LoadProvider(addressables, providerData, providerSuffix);
                    }
                }
                if (addressables.InstanceProvider == null)
                {
                    var prov = data.InstanceProviderData.CreateInstance <IInstanceProvider>();
                    if (prov != null)
                    {
                        addressables.InstanceProvider = prov;
                    }
                }
                if (addressables.SceneProvider == null)
                {
                    var prov = data.SceneProviderData.CreateInstance <ISceneProvider>();
                    if (prov != null)
                    {
                        addressables.SceneProvider = prov;
                    }
                }

                ResourceLocationMap locMap = data.CreateLocator(providerSuffix);
                addressables.AddResourceLocator(locMap, data.localHash, data.location);

                data.CleanData();
                return(addressables.ResourceManager.CreateCompletedOperation <IResourceLocator>(locMap, string.Empty));
            }
        }
Пример #10
0
    public void AssetBundleDownloadDependencies(AsyncOperationHandle <IResourceLocator> Content, bool RegisterComplete =
                                                true)
    {
        ResourceLocationMap locMap = Content.Result as ResourceLocationMap;

        HashSet <IResourceLocation> Tolode = new HashSet <IResourceLocation>();

        HashSet <IResourceLocation> FoundDependencies = new HashSet <IResourceLocation>();

        foreach (var Locator in locMap.Locations)
        {
            foreach (var Resource in Locator.Value)
            {
                if (Resource.HasDependencies)
                {
                    foreach (var Dependencie in Resource.Dependencies)
                    {
                        if (FoundDependencies.Contains(Dependencie) == false)                         //Check if it's a new dependency
                        {
                            FoundDependencies.Add(Dependencie);
                            Tolode.Add(
                                Resource);                                 //Then add this to the Load dependency thing idk why can't you Load the dependency directly
                        }
                    }
                }
            }
        }

        if (RegisterComplete)
        {
            var ContentLoadTracker = new LoadCounter(Tolode.Count, RegisterLoad);
            AddressableDownloadPopUp.DownloadDependencies(Tolode.ToList(), ContentLoadTracker);
        }

        else
        {
            AddressableDownloadPopUp.DownloadDependencies(Tolode.ToList());
        }
    }
Пример #11
0
        public IEnumerator VerifyDownloadSize()
        {
            yield return(Init());

            long expectedSize = 0;
            var  locMap       = new ResourceLocationMap();

            var bundleLoc1 = new ResourceLocationBase("sizeTestBundle1", "http://nowhere.com/mybundle1.bundle", typeof(AssetBundleProvider).FullName);
            var sizeData1  = (bundleLoc1.Data = CreateLocationSizeData("sizeTestBundle1", 1000, 123, "hashstring1")) as ILocationSizeData;

            if (sizeData1 != null)
            {
                expectedSize += sizeData1.ComputeSize(bundleLoc1);
            }

            var bundleLoc2 = new ResourceLocationBase("sizeTestBundle2", "http://nowhere.com/mybundle2.bundle", typeof(AssetBundleProvider).FullName);
            var sizeData2  = (bundleLoc2.Data = CreateLocationSizeData("sizeTestBundle2", 500, 123, "hashstring2")) as ILocationSizeData;

            if (sizeData2 != null)
            {
                expectedSize += sizeData2.ComputeSize(bundleLoc2);
            }

            var assetLoc = new ResourceLocationBase("sizeTestAsset", "myASset.asset", typeof(BundledAssetProvider).FullName, bundleLoc1, bundleLoc2);

            locMap.Add("sizeTestBundle1", bundleLoc1);
            locMap.Add("sizeTestBundle2", bundleLoc2);
            locMap.Add("sizeTestAsset", assetLoc);
            m_Addressables.ResourceLocators.Add(locMap);

            var dOp = m_Addressables.GetDownloadSize("sizeTestAsset");

            yield return(dOp);

            Assert.AreEqual(expectedSize, dOp.Result);
            dOp.Release();
        }
Пример #12
0
 void LoadOpComplete(AsyncOperationHandle <IResourceLocator> op, IList <IResourceLocation> catalogs, ResourceLocationMap locMap, int index)
 {
     if (op.Result != null)
     {
         m_Addressables.RemoveResourceLocator(locMap);
         Result = op.Result;
         Complete(Result, true, string.Empty);
         m_Addressables.Release(op);
         Addressables.Log("Addressables - initialization complete.");
     }
     else
     {
         Addressables.LogFormat("Addressables - failed to load content catalog from {0}.", op);
         if (index + 1 >= catalogs.Count)
         {
             Addressables.LogWarningFormat("Addressables - initialization failed.", op);
             m_Addressables.RemoveResourceLocator(locMap);
             Complete(Result, false, op.OperationException != null ? op.OperationException.Message : "LoadContentCatalogInternal");
             m_Addressables.Release(op);
         }
         else
         {
             m_loadCatalogOp = LoadContentCatalogInternal(catalogs, index + 1, locMap);
             m_Addressables.Release(op);
         }
     }
 }
Пример #13
0
        //Attempts to load each catalog in order, stopping at first success.
        AsyncOperationHandle <IResourceLocator> LoadContentCatalogInternal(IList <IResourceLocation> catalogs, int index, ResourceLocationMap locMap)
        {
            Addressables.LogFormat("Addressables - loading content catalog from {0}.", m_Addressables.ResourceManager.TransformInternalId(catalogs[index]));
            var loadOp = LoadContentCatalog(catalogs[index], m_ProviderSuffix);

            if (loadOp.IsDone)
            {
                LoadOpComplete(loadOp, catalogs, locMap, index);
            }
            else
            {
                loadOp.Completed += op => LoadOpComplete(op, catalogs, locMap, index);
            }
            return(loadOp);
        }
Пример #14
0
        public static IEnumerator Start()
        {
            float startTime = Time.realtimeSinceStartup;

#if (UNITY_EDITOR && !USE_CDN) || DISABLE_CDN
            yield break;
#endif
            //初始化AAS
            yield return(Addressables.InitializeAsync());

            LogTimeDurFormat("Addressables.InitializeAsync", ref startTime, true);
            //修改provider fixed AAS bug
            foreach (var provider in Addressables.ResourceManager.ResourceProviders)
            {
                if (typeof(TextDataProvider).IsAssignableFrom(provider.GetType()))
                {
                    (provider as TextDataProvider).IgnoreFailures = false;
                }
            }

            LogTimeDurFormat("foreach Addressables.ResourceManager.ResourceProviders ", ref startTime, true);
            //拉取本地资源版本号
            var localVersion = Application.version;
            if (File.Exists(localVersionPath))
            {
                var localVersionHandle = LoadText(localVersionPath, "LocalVersion");;
                yield return(localVersionHandle);

                localVersion = localVersionHandle.Result;
                Addressables.Release(localVersionHandle);
            }
            var localResVersion = ResVersion.parseVersion(localVersion);
            var libResVersion   = ResVersion.parseVersion(Application.version);

            LogFormat("local version:{0},library version:{1}", localVersion, Application.version);
            if (null == localResVersion || null == libResVersion)
            {
                yield break;
            }

            //包内版本大于本地持续化版本号(安装了新包) 清除本地缓存数据
            if (libResVersion.high > localResVersion.high || libResVersion.mid > localResVersion.mid)
            {
                LogFormat("清除本地缓存");
                Caching.ClearCache();
                File.Delete(localCatalogPath);
                File.Delete(localVersionPath);
                File.Delete(PersistCDNConfigPath);
                if (Directory.Exists(LocalHotAssetBundlePath))
                {
                    Directory.Delete(LocalHotAssetBundlePath, true);
                }

                //yield break;
            }
            LogTimeDurFormat("load localVersion", ref startTime, true);
            //读取CDN 地址配置
            yield return(LoadCDNConfig());

            LogTimeDurFormat("load cdn config", ref startTime, true);
            //拉取CDN资源版本号
            var remoteVersionHandle = LoadText(remoteVersionUrl, "RemoteVersion");
            yield return(remoteVersionHandle);

            var remoteVersion = remoteVersionHandle.Result;
            Addressables.Release(remoteVersionHandle);
            LogTimeDurFormat("load remoteVersion", ref startTime, true);
            if (null == remoteVersion)
            {
                LogErrorFormat("远程资源版本号加载失败");
                yield break;
            }
            LogFormat("remoteVersion:{0}", remoteVersion);

            var remoteResVersion = ResVersion.parseVersion(remoteVersion);
            if (null == remoteResVersion)
            {
                yield break;
            }
            if (remoteResVersion.high < localResVersion.high || (remoteResVersion.high == localResVersion.high && remoteResVersion.mid < localResVersion.mid))
            {
                LogFormat("服务器资源版本过低");
                yield break;
            }
            if (remoteResVersion.high > localResVersion.high || remoteResVersion.mid > localResVersion.mid)
            {
                LogFormat("需要更新整包");
                yield break;
            }
            else if (remoteResVersion.small > localResVersion.small)
            {
                LogFormat("need hot update");
                //拉取CDN catalog 信息
                LogFormat("remoteCatalogUrl:" + remoteCatalogUrl);
                var remoteCatalogHandle = LoadText(remoteCatalogUrl, "RemoteCatalog");
                yield return(remoteCatalogHandle);

                var remoteCatalog = remoteCatalogHandle.Result;
                Addressables.Release(remoteCatalogHandle);
                if (null == remoteCatalog)
                {
                    LogErrorFormat("远程资源加载失败");
                    yield break;
                }

                //将最近的catalog缓存到本地持续化目录
                File.WriteAllText(localCatalogPath, remoteCatalog);
                File.WriteAllText(localVersionPath, remoteVersion);
                LogTimeDurFormat("load remote catalog", ref startTime, true);
            }
            LogFormat("localCatalogPath:" + localCatalogPath);
            //本地持续化目录没有缓存catalog
            if (!File.Exists(localCatalogPath))
            {
                yield break;
            }

            //对比catalog 解析出需要热更的bundle
            LogFormat("localCatalogPath:" + localCatalogPath);
            var localCatalogLocation = new ResourceLocationBase("LocalCatalog", localCatalogPath, typeof(JsonAssetProvider).FullName, typeof(ContentCatalogData));
            var localCatalogHandle   = Addressables.LoadAssetAsync <ContentCatalogData>(localCatalogLocation);
            yield return(localCatalogHandle);

            var data = localCatalogHandle.Result;
            Addressables.Release(localCatalogHandle);
            LogTimeDurFormat("load local catalog", ref startTime, true);

            ResourceLocationMap RemoteMap = data.CreateLocator(null);
            var newBundles = parseBundleList(RemoteMap, "remote");
            LogTimeDurFormat("foreach remote catalog", ref startTime, true);
            dirtyBundle = null;
            // Addressables.CheckForCatalogUpdates(false);
            foreach (ResourceLocationMap item in Addressables.ResourceLocators)
            {
                if ("AddressablesMainContentCatalog" == item.LocatorId)
                {
                    var oldBundles = parseBundleList(item, "local");
                    LogTimeDurFormat("load local catalog", ref startTime, true);
                    dirtyBundle = compareResLocation(newBundles, oldBundles);
                    Addressables.RemoveResourceLocator(item);
                    Addressables.AddResourceLocator(RemoteMap);
                    LogTimeDurFormat("compare catalog", ref startTime, true);
                    break;
                }
            }

            if (null == dirtyBundle || 0 == dirtyBundle.Count)
            {
                yield break;
            }

            //该方法计算下载大小只对远程bundle有用
            //long size = 0;
            //foreach (var key in dirtyBundle)
            //{
            //    IResourceLocation location;
            //    newBundles.TryGetValue(key, out location);
            //    var sizeData = location.Data as ILocationSizeData;
            //    if (sizeData != null)
            //        size += sizeData.ComputeSize(location, Addressables.ResourceManager);
            //}
            // LogFormat("需要下载的补丁大小:{0}", size);

            yield return(DownLoadRemoteAssetBundles(dirtyBundle));

            LogTimeDurFormat("dowmload hot file", ref startTime, true);
            Addressables.InternalIdTransformFunc = convertBundleInternalId;
            LogFormat("下载完,预加载到内存");
            AsyncOperationHandle handler = Addressables.DownloadDependenciesAsync(dirtyBundle, Addressables.MergeMode.Union);
            while (!handler.IsDone)
            {
                yield return(null);
            }
            Addressables.Release(handler);
            LogTimeDurFormat("download dependency", ref startTime, true);
            yield return(null);
        }
Пример #15
0
        public static string GetAddressables()
        {
            ResourceLocationMap map = Addressables.ResourceLocators as ResourceLocationMap;

            return(string.Join(", ", map.Keys.ToList()));
        }
        protected override void Execute()
        {
            Addressables.LogFormat("Addressables - runtime data operation completed with status = {0}, result = {1}.", m_rtdOp.Status, m_rtdOp.Result);
            if (m_rtdOp.Result == null)
            {
                Addressables.LogWarningFormat("Addressables - Unable to load runtime data at location {0}.", m_rtdOp);
                Complete(m_Result, false, string.Format("Addressables - Unable to load runtime data at location {0}.", m_rtdOp));
                return;
            }
            var rtd = m_rtdOp.Result;

            m_Addressables.Release(m_rtdOp);
            if (rtd.CertificateHandlerType != null)
            {
                m_Addressables.ResourceManager.CertificateHandlerInstance = Activator.CreateInstance(rtd.CertificateHandlerType) as CertificateHandler;
            }

#if UNITY_EDITOR
            if (UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString() != rtd.BuildTarget)
            {
                Addressables.LogErrorFormat("Addressables - runtime data was built with a different build target.  Expected {0}, but data was built with {1}.  Certain assets may not load correctly including shaders.  You can rebuild player content via the Addressable Assets window.", UnityEditor.EditorUserBuildSettings.activeBuildTarget, rtd.BuildTarget);
            }
#endif
            if (!rtd.LogResourceManagerExceptions)
            {
                ResourceManager.ExceptionHandler = null;
            }

            if (!rtd.ProfileEvents)
            {
                m_Diagnostics.Dispose();
                m_Diagnostics = null;
            }

            //   DiagnosticEventCollector.ResourceManagerProfilerEventsEnabled = rtd.ProfileEvents;
            Addressables.Log("Addressables - loading initialization objects.");
            foreach (var i in rtd.InitializationObjects)
            {
                if (i.ObjectType.Value == null)
                {
                    Addressables.LogFormat("Invalid initialization object type {0}.", i.ObjectType);
                    continue;
                }
                try
                {
                    var o = i.CreateInstance <object>();
                    Addressables.LogFormat("Initialization object {0} created instance {1}.", i, o);
                }
                catch (Exception ex)
                {
                    Addressables.LogErrorFormat("Exception thrown during initialization of object {0}: {1}", i, ex.ToString());
                }
            }

            var locMap = new ResourceLocationMap(rtd.CatalogLocations);
            m_Addressables.ResourceLocators.Add(locMap);
            IList <IResourceLocation> catalogs;
            if (!locMap.Locate(ResourceManagerRuntimeData.kCatalogAddress, typeof(ContentCatalogData), out catalogs))
            {
                Addressables.LogWarningFormat("Addressables - Unable to find any catalog locations in the runtime data.");
                m_Addressables.ResourceLocators.Remove(locMap);
                Complete(m_Result, false, "Addressables - Unable to find any catalog locations in the runtime data.");
            }
            else
            {
                Addressables.LogFormat("Addressables - loading content catalogs, {0} found.", catalogs.Count);
                LoadContentCatalogInternal(catalogs, 0, locMap);
            }
        }
        //Attempts to load each catalog in order, stopping at first success.
        internal AsyncOperationHandle <IResourceLocator> LoadContentCatalogInternal(IList <IResourceLocation> catalogs, int index, ResourceLocationMap locMap, IResourceLocation remoteHashLocation)
        {
            Addressables.LogFormat("Addressables - loading content catalog from {0}.", m_Addressables.ResourceManager.TransformInternalId(catalogs[index]));
            var loadOp = LoadContentCatalog(catalogs[index], m_ProviderSuffix, remoteHashLocation);

            if (loadOp.IsDone)
            {
                LoadOpComplete(loadOp, catalogs, locMap, index, remoteHashLocation);
            }
            else
            {
                loadOp.Completed += op =>
                {
                    LoadOpComplete(op, catalogs, locMap, index, remoteHashLocation);
                }
            };
            return(loadOp);
        }

        void LoadOpComplete(AsyncOperationHandle <IResourceLocator> op, IList <IResourceLocation> catalogs, ResourceLocationMap locMap, int index, IResourceLocation remoteHashLocation)
        {
            if (op.Result != null)
            {
                m_Addressables.RemoveResourceLocator(locMap);
                Result = op.Result;
                Complete(Result, true, string.Empty);
                m_Addressables.Release(op);
                Addressables.Log("Addressables - initialization complete.");
            }
            else
            {
                Addressables.LogFormat("Addressables - failed to load content catalog from {0}.", op);
                if (index + 1 >= catalogs.Count)
                {
                    Addressables.LogWarningFormat("Addressables - initialization failed.", op);
                    m_Addressables.RemoveResourceLocator(locMap);
                    if (op.OperationException != null)
                    {
                        Complete(Result, false, op.OperationException);
                    }
                    else
                    {
                        Complete(Result, false, "LoadContentCatalogInternal");
                    }
                    m_Addressables.Release(op);
                }
                else
                {
                    m_loadCatalogOp = LoadContentCatalogInternal(catalogs, index + 1, locMap, remoteHashLocation);
                    m_Addressables.Release(op);
                }
            }
        }
    }
 //Attempts to load each catalog in order, stopping at first success.
 void LoadContentCatalogInternal(IList <IResourceLocation> catalogs, int index, ResourceLocationMap locMap)
 {
     Addressables.LogFormat("Addressables - loading content catalog from {0}.", catalogs[index].InternalId);
     LoadContentCatalog(catalogs[index], m_ProviderSuffix).Completed += op =>
     {
         if (op.Result != null)
         {
             m_Addressables.RemoveResourceLocator(locMap);
             Result = op.Result;
             Complete(Result, true, string.Empty);
             m_Addressables.Release(op);
             Addressables.Log("Addressables - initialization complete.");
         }
         else
         {
             Addressables.LogFormat("Addressables - failed to load content catalog from {0}.", op);
             if (index + 1 >= catalogs.Count)
             {
                 Addressables.LogWarningFormat("Addressables - initialization failed.", op);
                 m_Addressables.RemoveResourceLocator(locMap);
                 Complete(Result, false, op.OperationException != null ? op.OperationException.Message : "LoadContentCatalogInternal");
                 m_Addressables.Release(op);
             }
             else
             {
                 LoadContentCatalogInternal(catalogs, index + 1, locMap);
                 m_Addressables.Release(op);
             }
         }
     };
 }
        protected override void Execute()
        {
            Addressables.LogFormat("Addressables - runtime data operation completed with status = {0}, result = {1}.", m_rtdOp.Status, m_rtdOp.Result);
            if (m_rtdOp.Result == null)
            {
                Addressables.LogWarningFormat("Addressables - Unable to load runtime data at location {0}.", m_rtdOp);
                Complete(Result, false, string.Format("Addressables - Unable to load runtime data at location {0}.", m_rtdOp));
                return;
            }
            Addressables.LogFormat("Initializing Addressables version {0}.", m_rtdOp.Result.AddressablesVersion);
            var rtd = m_rtdOp.Result;

            m_Addressables.ResourceManager.postProfilerEvents = rtd.ProfileEvents;
            WebRequestQueue.SetMaxConcurrentRequests(rtd.MaxConcurrentWebRequests);
            m_Addressables.CatalogRequestsTimeout = rtd.CatalogRequestsTimeout;
            foreach (var catalogLocation in rtd.CatalogLocations)
            {
                if (catalogLocation.Data != null && catalogLocation.Data is ProviderLoadRequestOptions loadData)
                {
                    loadData.WebRequestTimeout = rtd.CatalogRequestsTimeout;
                }
            }

            m_Addressables.Release(m_rtdOp);
            if (rtd.CertificateHandlerType != null)
            {
                m_Addressables.ResourceManager.CertificateHandlerInstance = Activator.CreateInstance(rtd.CertificateHandlerType) as CertificateHandler;
            }

#if UNITY_EDITOR
            if (UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString() != rtd.BuildTarget)
            {
                Addressables.LogErrorFormat("Addressables - runtime data was built with a different build target.  Expected {0}, but data was built with {1}.  Certain assets may not load correctly including shaders.  You can rebuild player content via the Addressables window.", UnityEditor.EditorUserBuildSettings.activeBuildTarget, rtd.BuildTarget);
            }
#endif
            if (!rtd.LogResourceManagerExceptions)
            {
                ResourceManager.ExceptionHandler = null;
            }

            if (!rtd.ProfileEvents)
            {
                m_Diagnostics.Dispose();
                m_Diagnostics = null;
                m_Addressables.ResourceManager.ClearDiagnosticCallbacks();
            }

            Addressables.Log("Addressables - loading initialization objects.");

            ContentCatalogProvider ccp = m_Addressables.ResourceManager.ResourceProviders
                                         .FirstOrDefault(rp => rp.GetType() == typeof(ContentCatalogProvider)) as ContentCatalogProvider;
            if (ccp != null)
            {
                ccp.DisableCatalogUpdateOnStart = rtd.DisableCatalogUpdateOnStartup;
                ccp.IsLocalCatalogInBundle      = rtd.IsLocalCatalogInBundle;
            }

            var locMap = new ResourceLocationMap("CatalogLocator", rtd.CatalogLocations);
            m_Addressables.AddResourceLocator(locMap);
            IList <IResourceLocation> catalogs;
            if (!locMap.Locate(ResourceManagerRuntimeData.kCatalogAddress, typeof(ContentCatalogData), out catalogs))
            {
                Addressables.LogWarningFormat(
                    "Addressables - Unable to find any catalog locations in the runtime data.");
                m_Addressables.RemoveResourceLocator(locMap);
                Complete(Result, false, "Addressables - Unable to find any catalog locations in the runtime data.");
            }
            else
            {
                Addressables.LogFormat("Addressables - loading content catalogs, {0} found.", catalogs.Count);
                IResourceLocation remoteHashLocation = null;
                if (catalogs[0].Dependencies.Count == 2 && rtd.DisableCatalogUpdateOnStartup)
                {
                    remoteHashLocation = catalogs[0].Dependencies[(int)ContentCatalogProvider.DependencyHashIndex.Remote];
                    catalogs[0].Dependencies[(int)ContentCatalogProvider.DependencyHashIndex.Remote] = catalogs[0].Dependencies[(int)ContentCatalogProvider.DependencyHashIndex.Cache];
                }
                m_loadCatalogOp = LoadContentCatalogInternal(catalogs, 0, locMap, remoteHashLocation);
            }
        }