private IEnumerator DownloadAsync()
    {
        long downloadedSize = 0;

        for (int i = 0; i < updateKeys.Count; i++)
        {
            var downloadSizeHandle = Addressables.GetDownloadSizeAsync(updateKeys[i]);
            yield return(downloadSizeHandle);

            long size = downloadSizeHandle.Result;
            Addressables.Release(downloadSizeHandle);
            if (size <= 0)
            {
                continue;
            }

            var downloadHandle = Addressables.DownloadDependenciesAsync(updateKeys[i]);
            while (downloadHandle.PercentComplete < 1 && !downloadHandle.IsDone)
            {
                OnDownload?.Invoke(downloadedSize + (long)(downloadHandle.PercentComplete * size), downloadSize);
#if UNITY_EDITOR
                Debug.Log(string.Format("Download Size: {0}/{1}", downloadedSize + (long)(downloadHandle.PercentComplete * size), downloadSize));
#endif
                yield return(null);
            }
            downloadedSize += size;
            Addressables.Release(downloadHandle);
            if (downloadedSize >= downloadSize)
            {
                break;
            }
        }
    }
Example #2
0
 void example()
 {
     #region doc_DownloadSize
     AsyncOperationHandle <long> getDownloadSize =
         Addressables.GetDownloadSizeAsync(key);
     #endregion
 }
Example #3
0
        IEnumerator UpdateAssets(object[] keys)
        {
            var sizeHandle = Addressables.GetDownloadSizeAsync(keys);

            yield return(sizeHandle);

/*            BootScreen.Instance.SetLabel("正在更新资源...");
 *          BootScreen.Instance.SetProgress(0);*/

            long totalDownloadSize = sizeHandle.Result;

            if (totalDownloadSize > 0)
            {
                var downloadHandle = Addressables.DownloadDependenciesAsync(keys, Addressables.MergeMode.Union);

                while (!downloadHandle.IsDone)
                {
                    float percent = downloadHandle.PercentComplete;

/*                    BootScreen.Instance.SetProgress(percent);
 *                  BootScreen.Instance.SetLabel(($"正在更新资源({(int)(totalDownloadSize * percent)}/{totalDownloadSize})..."));*/
                }
            }
            yield return(null);
        }
Example #4
0
    private void OnDownloadAR_scene(AsyncOperationHandle <IList <IResourceLocation> > obj)
    {
        AR_scene = new List <IResourceLocation>(obj.Result);

        Debug.Log(AR_scene[0]);

        downloadSize = Addressables.GetDownloadSizeAsync(AR_scene[0]);
        Debug.Log(downloadSize.Result);
        DownloadScene_Size1.text = downloadSize.Result.ToString();
        DownloadScene_Size2.text = downloadSize.Result.ToString();


        if (downloadSize.Result > 0)
        {
            // Delete old Bundle hahaha
            //Caching.ClearCache();

            Caching.ClearAllCachedVersions("remote_arscene_scenes_all");

            StartCoroutine(LoadRoutine());
        }
        else
        {
            Debug.Log("There is no Update");
            Addressables.LoadSceneAsync(AR_scene[0]);
        }
    }
    void LocateResourcesPatch()
    {
        Debug.Log("Locating resource....");
        foreach (var item in Addressables.ResourceLocators)
        {
            //Debug.LogWarning(item + " || " + item.Keys + " || " + item.LocatorId + " || " + item.Keys.Count());

            if (item.GetType() == typeof(ResourceLocationMap))
            {
                //ResourceLocationMap map = (ResourceLocationMap)item;
                Dictionary <object, IList <IResourceLocation> > locations = map.Locations;

                foreach (var loc in locations)
                {
                    //Debug.Log(loc.Key + " || " + loc.Value + " || " + loc.Value[0].PrimaryKey + " || " + loc.Value[0].DependencyHashCode);
                    if (loc.Key.Equals("default"))
                    {
                        Debug.Log("Found the packet!");

                        foundpacket = true;
                        downloadKey = loc.Key.ToString();

                        Addressables.GetDownloadSizeAsync(downloadKey).Completed += OnGettingDownloadSize;
                        UI_MANAGER.Initialise(OnDownload, OnDownloadReject);
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }
    }
        /// <summary>
        /// <para>指定されたアドレスもしくはラベルに紐づくアセットバンドルのサイズを取得します</para>
        /// <para>キャッシュに存在するアセットバンドルのサイズは 0 で返ってくるため</para>
        /// <para>ダウンロードが必要なアセットバンドルのサイズの合計が取得できます</para>
        /// <para>既に読み込んだリモートカタログを使用してサイズの計算を行うため、通信は行いません</para>
        /// <para>存在しないアドレスやラベルを指定すると onFailure が呼び出されます</para>
        /// </summary>
        public AddressablesControllerHandle <long> GetDownloadSizeAsync(IList <object> addressesOrLabels)
        {
            var source = new TaskCompletionSource <(long, AddressablesControllerResultCode)>();

            void OnFailure(AddressablesControllerResultCode resultCode)
            {
                source.TrySetResult((0, resultCode));
            }

            if (!m_isInitialized)
            {
                OnFailure(AddressablesControllerResultCode.FAILURE_NOT_INITIALIZED);
                return(new AddressablesControllerHandle <long>(source.Task));
            }

            var isFailure     = false;
            var isNotExistKey = false;

            void OnComplete(AsyncOperationHandle <long> handle)
            {
                m_exceptionHandler -= ExceptionHandler;

                if (isFailure)
                {
                    var resultCode = isNotExistKey
                                                        ? AddressablesControllerResultCode.FAILURE_KEY_NOT_EXIST
                                                        : AddressablesControllerResultCode.FAILURE_CANNOT_CONNECTION
                    ;

                    OnFailure(resultCode);
                    return;
                }

                if (handle.Status != AsyncOperationStatus.Succeeded)
                {
                    OnFailure(AddressablesControllerResultCode.FAILURE_UNKNOWN);
                    return;
                }

                source.TrySetResult((handle.Result, AddressablesControllerResultCode.SUCCESS));
            }

            void ExceptionHandler(Exception exception)
            {
                isFailure     = true;
                isNotExistKey = exception.Message.Contains(nameof(InvalidKeyException));

                m_exceptionHandler -= ExceptionHandler;
            }

            m_exceptionHandler += ExceptionHandler;

            // アドレスもしくはラベルは IList<object> 型で受け取る必要があります
            // IList<string> 型で渡すとサイズの取得に失敗します
            var result = Addressables.GetDownloadSizeAsync(( IEnumerable )addressesOrLabels);

            result.Completed += handle => OnComplete(handle);

            return(new AddressablesControllerHandle <long>(result, source.Task));
        }
    public void LoadScene(string tag)
    {
        Debug.Log("Addressables Procedure Started for Loading Scene: " + tag + "@" + Time.time);
        Addressables.ClearDependencyCacheAsync(tag);
        Addressables.InitializeAsync().Completed += delegate {
            Debug.Log("Addressables.InitializeAsync.Completed:@" + Time.time);
            Addressables.GetDownloadSizeAsync(tag).Completed += delegate(AsyncOperationHandle <long> obj)
            {
                Debug.Log("Addressables.GetDownloadSizeAsync.Completed:@" + Time.time);
                float downloadSizeInMB = (float)obj.Result / 1024 / 1024;
                Debug.Log("GetDownloadSizeAsync: " + obj.Result + " bytes, which is " + downloadSizeInMB + " MB");

                if (size)
                {
                    size.text += System.Environment.NewLine + "Size of download: " + downloadSizeInMB.ToString();
                }

                Addressables.DownloadDependenciesAsync(tag).Completed += delegate(AsyncOperationHandle opDownloadDependencies)
                {
                    Debug.Log("Addressables.DownloadDependenciesAsync.Completed:" + opDownloadDependencies.Status + "@" + Time.time);
                    Addressables.LoadSceneAsync(tag).Completed += delegate(AsyncOperationHandle <SceneInstance> opLoadScene) {
                        Debug.Log("LoadSceneAsync.Completed: " + opLoadScene.Status + "@" + Time.time);
                        if (opLoadScene.Status == AsyncOperationStatus.Succeeded)
                        {
                        }
                    };
                };
            };
        };
    }
Example #8
0
    public IEnumerator DownAssetImpl()
    {
        var downloadsize = Addressables.GetDownloadSizeAsync((IEnumerable)_updateKeys);

        yield return(downloadsize);

        Debug.Log("start download size :" + downloadsize.Result);
        DownloadPercent.text = "start download size :" + downloadsize.Result;

        if (downloadsize.Result > 0)
        {
            _isDownloading  = true;
            _downloadHandle =
                Addressables.DownloadDependenciesAsync((IEnumerable)_updateKeys, Addressables.MergeMode.Union);
            yield return(_downloadHandle);

            //await download.Task;
            Debug.Log("download result type " + _downloadHandle.Result.GetType());
            foreach (var item in _downloadHandle.Result as
                     List <UnityEngine.ResourceManagement.ResourceProviders.IAssetBundleResource> )
            {
                var ab = item.GetAssetBundle();
                foreach (var name in ab.GetAllAssetNames())
                {
                    Debug.Log("asset name " + name);
                }
            }

            Addressables.Release(_downloadHandle);
        }

        _isDownloading = false;
        Addressables.Release(downloadsize);
    }
    private IEnumerator CalculateUpdateSizeAsync()
    {
        for (int i = 0; i < updateLocators.Count; i++)
        {
            IList <IResourceLocation> locations;
            var e = updateLocators[i].Keys.GetEnumerator();
            while (e.MoveNext())
            {
                if (updateLocators[i].Locate(e.Current, typeof(object), out locations))
                {
                    for (int j = 0; j < locations.Count; j++)
                    {
                        if (updateKeys.Contains(locations[j].PrimaryKey))
                        {
                            continue;
                        }
                        updateKeys.Add(locations[j].PrimaryKey);
                    }
                }
            }
        }
        var downloadSizeHandle = Addressables.GetDownloadSizeAsync(updateKeys);

        yield return(downloadSizeHandle);

        downloadSize = downloadSizeHandle.Result;
        Addressables.Release(downloadSizeHandle);
    }
    public IEnumerator DownAssetImpl()
    {
        var downloadsize = Addressables.GetDownloadSizeAsync(_updateKeys);

        yield return(downloadsize);

        Debug.Log("start download size :" + downloadsize.Result);
        if (downloadsize.Result > 0)
        {
            var download = Addressables.DownloadDependenciesAsync(_updateKeys, Addressables.MergeMode.Intersection);
            yield return(download);

            //await download.Task;
            Debug.Log("download result type " + download.Result.GetType());
            foreach (var item in download.Result as List <UnityEngine.ResourceManagement.ResourceProviders.IAssetBundleResource> )
            {
                var ab = item.GetAssetBundle();
                Debug.Log("ab name " + ab.name);
                foreach (var name in ab.GetAllAssetNames())
                {
                    Debug.Log("asset name " + name);
                }
            }
            Addressables.Release(download);
        }
        Addressables.Release(downloadsize);
    }
        private IEnumerator DownloadInner(AddressableDownloadLabelData downloadLabelData)
        {
            Debug.Log($"Addressable start to download {downloadLabelData.Label}");
            _currentLabel = downloadLabelData;

            var locations = Addressables.LoadResourceLocationsAsync(downloadLabelData.Label);

            yield return(locations);

            var getDownloadSize = Addressables.GetDownloadSizeAsync(locations.Result);

            yield return(getDownloadSize);

            _fullSize = (int)((float)getDownloadSize.Result / Mb);
            Debug.Log($"Addressable {downloadLabelData.Label} download size: {_fullSize}");

            if (_fullSize > 0)
            {
                var downloadLocations = Addressables.DownloadDependenciesAsync(locations.Result);
                while (!downloadLocations.IsDone)
                {
                    _progress       = downloadLocations.PercentComplete;
                    _downloadedSize = (int)(_progress * _fullSize * Mb);
                    downloadLabelData.SetProgress(_downloadedSize, _fullSize, _progress);
                    //Debug.Log($"Addressable {label} downloading {_progress * 100}% size {_downloadedSize}");
                    yield return(new WaitForSeconds(0.01f));
                }
                downloadLabelData.SetDone();
            }
            else
            {
                Debug.Log($"Addressable already to downloaded {downloadLabelData.Label}");
                downloadLabelData.SetDone();
            }
        }
Example #12
0
        private IEnumerator DownloadFiles(List <string> catalogs)
        {
            foreach (string s in catalogs)
            {
                var handle = Addressables.GetDownloadSizeAsync(catalogs);
                while (!handle.IsDone)
                {
                    yield return(new WaitForFixedUpdate());
                }

                float catalogSize = handle.Result;
                float prevPercent = 0;
                var   newhandle   = Addressables.DownloadDependenciesAsync(catalogs);
                while (!newhandle.IsDone)
                {
                    prevPercent              = newhandle.PercentComplete;
                    m_currentDownloadedSize += catalogSize * (newhandle.PercentComplete - prevPercent);

                    m_updateCheckerView.UpdateDownloadInfos(
                        1 / (m_downloadSize / m_currentDownloadedSize),
                        m_currentDownloadedSize,
                        m_downloadSize
                        );

                    yield return(new WaitForFixedUpdate());
                }
            }

            OnDownloadComplete();
        }
Example #13
0
    IEnumerator CheckDownloadSize(IList <IResourceLocation> locations)
    {
        // Prepare the actual operation
        AsyncOperationHandle <long> handle = Addressables.GetDownloadSizeAsync(locations);

        // Fire the async operation
        yield return(handle);

        Debug.Log("Size of assets to be downloaded (if zero, all are cached): " + handle.Result);
    }
Example #14
0
        public ETTask <long> GetDownLoadSize()
        {
            ETTaskCompletionSource <long> tcs    = new ETTaskCompletionSource <long>();
            AsyncOperationHandle <long>   update = Addressables.GetDownloadSizeAsync("A");

            update.Completed += download =>
            {
                tcs.SetResult(download.Result);
            };
            return(tcs.Task);
        }
Example #15
0
    public static async Task <float> GetTotalDownloadSize(List <AssetReference> assetList)
    {
        var totalSize = 0f;

        foreach (var asset in assetList)
        {
            var   task = Addressables.GetDownloadSizeAsync(asset).Task;
            await task;
            totalSize += task.Result;
        }

        return(totalSize);
    }
Example #16
0
    private IEnumerator GetSizeSceneRoutine(string sceneName, Action <long> onSuccess, Action <string> onFail)
    {
        var sizeOperationHandle = Addressables.GetDownloadSizeAsync(sceneName);

        while (sizeOperationHandle.IsValid() && !sizeOperationHandle.IsDone)
        {
            Debug.Log("Size estimation... " + sizeOperationHandle.PercentComplete * 100f);
            yield return(new WaitForSecondsRealtime(0.1f));
        }
        Debug.Log(sceneName + " size = " + sizeOperationHandle.Result);
        StopGetSizeScene();
        onSuccess.Invoke(sizeOperationHandle.Result);
    }
        private IEnumerator PreloadAssets() {
            #region doc_Download
            string key = "assetKey";

            // Check the download size
            AsyncOperationHandle<long> getDownloadSize = Addressables.GetDownloadSizeAsync(key);
            yield return getDownloadSize;

            //If the download size is greater than 0, download all the dependencies.
            if (getDownloadSize.Result > 0) {
                AsyncOperationHandle downloadDependencies = Addressables.DownloadDependenciesAsync(key);
                yield return downloadDependencies;
            }
            #endregion
        }
Example #18
0
        public async ETTask CheckDownLoadSize()
        {
            var size = Addressables.GetDownloadSizeAsync("default");
            await size.Task;

            if (size.Result != 0)
            {
                DownLoadSize.text = ConventToSize(size.Result);
                TotalSize         = size.Result;
            }
            else
            {
                Info.text = "无需更新.......";
            }
        }
Example #19
0
        /// <summary>
        /// 获取下载的资源大小
        /// </summary>
        public static long GetDownloadSize(IEnumerable keys)
        {
            var handle = Addressables.GetDownloadSizeAsync(keys);

            handle.WaitForCompletion();
            long downloadSize = 0;

            if (handle.Status == AsyncOperationStatus.Succeeded)
            {
                downloadSize = handle.Result;
            }

            Addressables.Release(handle);
            return(downloadSize);
        }
Example #20
0
        private IEnumerator Update(List <object> keyList)
        {
            AsyncOperationHandle <long> downloadSizeHandle = Addressables.GetDownloadSizeAsync(keyList);

            yield return(downloadSizeHandle);

            if (downloadSizeHandle.Status == AsyncOperationStatus.Succeeded && downloadSizeHandle.Result > 0)
            {
                AsyncOperationHandle downloadDependenciesHandle = Addressables.DownloadDependenciesAsync(keyList, Addressables.MergeMode.Union);
                yield return(downloadDependenciesHandle);

                Addressables.Release(downloadDependenciesHandle);
            }
            Addressables.Release(downloadSizeHandle);
        }
Example #21
0
    /// <summary>
    /// 这个方法和Addressables.UpdateCatalogs获取到的资源是一致的。
    /// </summary>
    async void StartUpdate()
    {
        Debug.Log("开始更新资源");
        IEnumerable <IResourceLocator> locators = Addressables.ResourceLocators;

        foreach (var item in locators)
        {
            var sizeHandle = Addressables.GetDownloadSizeAsync(item.Keys);
            await sizeHandle.Task;
            if (sizeHandle.Result > 0)
            {
                var downloadHandle = Addressables.DownloadDependenciesAsync(item.Keys, Addressables.MergeMode.Union);
                await downloadHandle.Task;
            }
        }
        Debug.Log("更新完成");
    }
Example #22
0
    //
    // Size Checking
    //

    public bool GetDownloadSize(List <string> keys, CheckSizeCallback cb)
    {
        // Get the download size of the list of keys, including their dependencies.

        if (running)
        {
            return(false);
        }
        running = true;

        checkSizeCallback = cb;

        sizeCheckHandle            = Addressables.GetDownloadSizeAsync(keys.ToArray());
        sizeCheckHandle.Completed += DownloadSizeComplete;

        return(true);
    }
Example #23
0
    /// <summary>
    /// ロード済みアセットリストをトレースログに書き出す
    /// 未完成
    /// </summary>
    public void TraceLoadedAssetList()
    {
        if (_LoadHandleList == null)
        {
            return;
        }
        List <AsyncOperationHandle <long> > coroutines = new List <AsyncOperationHandle <long> >();

        foreach (var key in _LoadHandleList.Keys)
        {
            string path      = _LoadHandleList[key].Path;
            var    coroutine = Addressables.GetDownloadSizeAsync(path);
            coroutine.Completed += (c) => { ComputeUnitSizeAsync(path, c); };
            coroutines.Add(coroutine);
        }
        StartCoroutine(ComputeSizeAsync(coroutines));
    }
Example #24
0
    public async void UpdateCatalog()
    {
        var start      = DateTime.Now;
        var initHandle = Addressables.InitializeAsync();
        await initHandle.Task;
        var checkHandle = Addressables.CheckForCatalogUpdates(false);
        await checkHandle.Task;

        Debug.Log(string.Format("CheckIfNeededUpdate use {0}ms", (DateTime.Now - start).Milliseconds));
        Debug.Log($"catalog count: {checkHandle.Result.Count} === check status: {checkHandle.Status}");
        if (checkHandle.Status == AsyncOperationStatus.Succeeded)
        {
            List <string> catalogs = checkHandle.Result;
            if (catalogs != null && catalogs.Count > 0)
            {
                needUpdateRes    = true;
                status_Text.text = "正在更新资源...";
                update_Slider.normalizedValue = 0f;
                update_Slider.gameObject.SetActive(true);
                start = DateTime.Now;
                AsyncOperationHandle <List <IResourceLocator> > updateHandle = Addressables.UpdateCatalogs(catalogs, false);
                await updateHandle.Task;
                var locators = updateHandle.Result;
                Debug.Log($"locator count: {locators.Count}");
                foreach (var v in locators)
                {
                    var sizeHandle = Addressables.GetDownloadSizeAsync(v.Keys);
                    await sizeHandle.Task;
                    long size = sizeHandle.Result;
                    Debug.Log($"download size:{size}");
                    if (size > 0)
                    {
                        //UINoticeTip.Instance.ShowOneButtonTip("更新提示", $"本次更新大小:{size}", "确定", null);
                        //yield return UINoticeTip.Instance.WaitForResponse();
                        downloadHandle = Addressables.DownloadDependenciesAsync(v.Keys, Addressables.MergeMode.Union);
                        await downloadHandle.Task;
                        Addressables.Release(downloadHandle);
                    }
                }
                Debug.Log(string.Format("UpdateFinish use {0}ms", (DateTime.Now - start).Milliseconds));
                Addressables.Release(updateHandle);
            }
            Addressables.Release(checkHandle);
        }
    }
Example #25
0
        async UniTask <long> IAssetDownloader.GetDownloadSize(IList <object> keys)
        {
            long totalSize = 0;

            foreach (var key in keys)
            {
                await Exist(key);

                var operation = Addressables.GetDownloadSizeAsync(key);
                if (!operation.IsDone)
                {
                    await operation.Task;
                }
                totalSize += operation.Result;
            }

            return(totalSize);
        }
        public async void CheckDownLoadSize()
        {
            var size = Addressables.GetDownloadSizeAsync("default");
            await size.Task;

            if (size.Result != 0)
            {
                DownLoadSize.text = FileHelper.ConventToSize(size.Result);
                TotalSize         = (long)(size.Result);
                ConfirmPanel.SetActive(true);
            }
            else
            {
                Info.text = "无需更新.......";
                InitScript.StartAsync();
                gameObject.SetActive(false);
            }
        }
Example #27
0
    public static IEnumerator UpdateLocalProtos(bool forceUpdate = false)
    {
        if (!Directory.Exists(ProtoConst.protoResDir))
        {
            Directory.CreateDirectory(ProtoConst.protoResDir);
        }

        var resHandle = Addressables.LoadResourceLocationsAsync(ProtoConst.label, typeof(TextAsset));

        yield return(resHandle);

        for (int i = 0; i < resHandle.Result.Count; i++)
        {
            string key = resHandle.Result[i].PrimaryKey;
            if (!key.StartsWith(ProtoConst.address))
            {
                continue;
            }
            string path = string.Format("{0}/{1}", ProtoConst.protoResDir, key.Substring(5, key.Length - 11));
            if (!forceUpdate && File.Exists(path))
            {
                var downloadSizeHandle = Addressables.GetDownloadSizeAsync(key);
                yield return(downloadSizeHandle);

                if (downloadSizeHandle.Result == 0)
                {
                    Addressables.Release(downloadSizeHandle); continue;
                }
            }
            var loadHandle = Addressables.LoadAssetAsync <TextAsset>(key);
            yield return(loadHandle);

            string dir = Path.GetDirectoryName(path);
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            File.WriteAllBytes(path, loadHandle.Result.bytes);
            Addressables.Release(loadHandle);
        }
        Addressables.Release(resHandle);
    }
Example #28
0
        //根据key来获取下载大小
        public ETTask <long> GetDownloadSizeAsync(string key)
        {
            ETTask <long> result = ETTask <long> .Create();

            var handle = Addressables.GetDownloadSizeAsync(key);

            handle.Completed += (res) =>
            {
                Addressables.Release(handle);
                if (handle.Status == AsyncOperationStatus.Failed)
                {
                    result.SetResult(-1);
                }
                else
                {
                    result.SetResult(handle.Result);
                }
            };
            return(result);
        }
Example #29
0
        public async ETTask Load()
        {
            // 预先加载的资源
            var resourceLocations = Addressables.LoadResourceLocationsAsync("preload");
            IList <IResourceLocation> locations = await resourceLocations.Task;

            // 预先下载的资源大小
            long downloadSize = await Addressables.GetDownloadSizeAsync("preload").Task;

            Log.Info($"预先下载资源大小:{downloadSize}");

            this.DownloadHandle = Addressables.DownloadDependenciesAsync(locations, false);

            this.TimerId = Game.Scene.GetComponent <TimerComponent>()
                           .NewRepeatedTimer(1000, b =>
            {
                var e = new ResUpdateEvent
                {
                    Percent = this.DownloadHandle.GetDownloadStatus().Percent, Status = this.DownloadHandle.Status,
                };

                EventBus.Publish(e);
            });

            await this.DownloadHandle.Task;
            TimerComponent.Instance.Remove(this.TimerId);

            // 加载完成事件
            EventBus.Publish(new ResUpdateEvent {
                Percent = this.DownloadHandle.GetDownloadStatus().Percent, Status = this.DownloadHandle.Status
            });

            // 资源下载完成,开始加载预加载资源。
            if (this.DownloadHandle.Status == AsyncOperationStatus.Succeeded)
            {
                await Preload();
            }

            // 清理
            Addressables.Release(this.DownloadHandle);
        }
Example #30
0
        /// <summary>
        /// 计算下载的资源
        /// </summary>
        IEnumerator ComputeDownload(List <IResourceLocator> locators, Action <bool> hotCallBack = null)
        {
            m_DownLoadList.Clear();
            foreach (var locator in locators)
            {
                //计算每个目录的所有的要下载的资源的大小
                AsyncOperationHandle allSizeHandle = Addressables.GetDownloadSizeAsync(locator.Keys);
                yield return(allSizeHandle);

                m_LoadSumSize += (long)allSizeHandle.Result;     //需要下载的资源的总大小

                if ((long)allSizeHandle.Result > 0)
                {
                    Debug.Log($"这个资源目录要更新的资源的大小 : {(long)allSizeHandle.Result}");

                    //这里的资源目录的keys里面给每个资源都保存了俩个key,一个是设置的名称,一个是hash值
                    foreach (var key in locator.Keys)
                    {
                        AsyncOperationHandle sizeHandle = Addressables.GetDownloadSizeAsync(key);
                        yield return(sizeHandle);

                        long totalDownloadSize = (long)sizeHandle.Result;
                        //Debug.Log($"资源:{key}==所在的AB包的大小" + totalDownloadSize);

                        //这里好坑,一个AB包里更新一个资源,这个包里其他资源的key获取下载大小也会返回包的大小
                        //这样会导致记录了很多无用的需要下载的资源的key,可以用分开打AB来解决这个问题,
                        //但是资源设置的名称和hash就没办法了,他们指向同一份资源
                        if (totalDownloadSize > 0)
                        {
                            m_DownLoadList.Add(key);
                        }
                        Addressables.Release(sizeHandle);
                    }
                }

                Addressables.Release(allSizeHandle);
            }

            hotCallBack(m_DownLoadList.Count > 0);
        }