< Summary

Class:MainScripts.DCL.AssetsEmbedment.Editor.EditorAssetBundlesDownloader
Assembly:AssetsEmbedmentEditor
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/AssetsEmbedment/Editor/EditorAssetBundlesDownloader.cs
Covered lines:0
Uncovered lines:24
Coverable lines:24
Total lines:66
Line coverage:0% (0 of 24)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DownloadAssetBundleWithDependenciesAsync()0%3061700%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/AssetsEmbedment/Editor/EditorAssetBundlesDownloader.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL;
 3using System.Collections.Generic;
 4using System.Linq;
 5using System.Threading;
 6using UnityEngine;
 7using UnityEngine.Networking;
 8
 9namespace MainScripts.DCL.AssetsEmbedment.Editor
 10{
 11    public static class EditorAssetBundlesDownloader
 12    {
 13        public static async UniTask<bool> DownloadAssetBundleWithDependenciesAsync(string baseUrl, string hash, Dictiona
 14        {
 015            if (loadedData.ContainsKey(hash))
 016                return true;
 17
 018            var url = $"{baseUrl}{hash}";
 19
 20            try
 21            {
 22                // Passing no extra arguments will bypass caching and crc checks
 023                var wr = await UnityWebRequest.Get(url).SendWebRequest();
 24
 025                if (wr.WebRequestSucceded())
 26                {
 027                    var data = wr.downloadHandler.data;
 028                    var assetBundle = await AssetBundle.LoadFromMemoryAsync(data);
 29
 30                    try
 31                    {
 032                        var dependencies = await assetBundle.GetDependenciesAsync(baseUrl, hash, CancellationToken.None)
 33
 034                        var result = await UniTask.WhenAll(dependencies.Select(d => DownloadAssetBundleWithDependenciesA
 35
 036                        if (result.All(r => r))
 37                        {
 038                            loadedData.Add(hash, data);
 039                            return true;
 40                        }
 041                    }
 42                    finally
 43                    {
 044                        if (assetBundle)
 45                        {
 046                            assetBundle.Unload(true);
 047                            Object.DestroyImmediate(assetBundle);
 48                        }
 49                    }
 50
 051                    return false;
 52                }
 53
 054                Debug.LogError(wr.error);
 055            }
 056            catch (UnityWebRequestException)
 57            {
 058                Debug.LogError($"Failed to download AB: {hash}. Url: {url}");
 59                // ignore for now
 060                return true;
 61            }
 62
 063            return false;
 064        }
 65    }
 66}