< Summary

Class:DCL.Asset_AB
Assembly:AssetPromiseKeeper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/AssetBundles/AB/Asset_AB.cs
Covered lines:29
Uncovered lines:5
Coverable lines:34
Total lines:92
Line coverage:85.2% (29 of 34)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Asset_AB()0%110100%
Clone()0%2100%
GetName()0%110100%
CancelShow()0%110100%
IsValid()0%110100%
Cleanup()0%220100%
GetAssetsByExtensions[T](...)0%550100%
AddAssetByExtension(...)0%3.213071.43%
SetAssetBundle(...)0%2100%
GetMetadata()0%110100%
LoadAllAssetsAsync()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/AssetBundles/AB/Asset_AB.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4namespace DCL
 5{
 6    public class Asset_AB : Asset
 7    {
 8        const string METADATA_FILENAME = "metadata.json";
 9
 10        private AssetBundle assetBundle;
 11        private Dictionary<string, List<Object>> assetsByExtension;
 12
 3013        public Asset_AB()
 14        {
 3015            assetsByExtension = new Dictionary<string, List<Object>>();
 3016        }
 17
 018        public override object Clone() => (Asset_AB) MemberwiseClone();
 1219        public string GetName() => assetBundle.name;
 20
 821        public void CancelShow() => Cleanup();
 2322        public bool IsValid() => assetBundle != null;
 23
 24        public override void Cleanup()
 25        {
 3826            assetsByExtension = null;
 27
 3828            if (assetBundle)
 29            {
 2330                assetBundle.Unload(true);
 2331                assetBundle = null;
 32            }
 3833        }
 34
 35        public List<T> GetAssetsByExtensions<T>(params string[] extensions)
 36            where T : Object
 37        {
 1538            var goList = new List<T>();
 39
 9040            for (int i1 = 0; i1 < extensions.Length; i1++)
 41            {
 3042                string ext = extensions[i1];
 43                List<Object> assets;
 44
 3045                if (assetsByExtension.ContainsKey(ext))
 46                {
 1347                    assets = assetsByExtension[ext];
 1348                    int glbCount = assets.Count;
 49
 5250                    for (int i = 0; i < glbCount; i++)
 51                    {
 1352                        Object go = assets[i];
 53
 1354                        if (go is T)
 1355                            goList.Add((T) go);
 56                    }
 57                }
 58            }
 59
 1560            return goList;
 61        }
 62        public void AddAssetByExtension(string ext, Object loadedAsset)
 63        {
 6764            if (assetsByExtension == null)
 65            {
 066                Debug.LogWarning($"Trying to add asset of type {ext} to unloaded AB");
 67
 068                return;
 69            }
 70
 6771            if (!assetsByExtension.ContainsKey(ext))
 72            {
 4873                assetsByExtension.Add(ext, new List<Object>());
 74            }
 75
 6776            assetsByExtension[ext].Add(loadedAsset);
 6777        }
 78        public void SetAssetBundle(AssetBundle ab)
 79        {
 080            assetBundle = ab;
 081        }
 82
 83        public TextAsset GetMetadata()
 84        {
 2385            return assetBundle.LoadAsset<TextAsset>(METADATA_FILENAME);
 86        }
 87        public AssetBundleRequest LoadAllAssetsAsync()
 88        {
 2289            return assetBundle.LoadAllAssetsAsync();
 90        }
 91    }
 92}