< 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:35
Uncovered lines:5
Coverable lines:40
Total lines:108
Line coverage:87.5% (35 of 40)
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%110100%
LoadMetrics()0%2.062075%
GetMetadata()0%2100%
LoadAllAssetsAsync()0%110100%
GetMetadata(...)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;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using Object = UnityEngine.Object;
 5
 6namespace DCL
 7{
 8    public class Asset_AB : Asset
 9    {
 10        const string METADATA_FILENAME = "metadata.json";
 11        const string METRICS_FILENAME = "metrics.json";
 12
 13        private AssetBundle assetBundle;
 14        private Dictionary<string, List<Object>> assetsByExtension;
 5415        public AssetBundleMetrics metrics { get; private set; } = new AssetBundleMetrics { meshesEstimatedSize = 0, anim
 16
 3017        public Asset_AB()
 18        {
 3019            assetsByExtension = new Dictionary<string, List<Object>>();
 3020        }
 21
 022        public override object Clone() => (Asset_AB) MemberwiseClone();
 1223        public string GetName() => assetBundle.name;
 24
 825        public void CancelShow() => Cleanup();
 2226        public bool IsValid() => assetBundle != null;
 27
 28        public override void Cleanup()
 29        {
 3830            assetsByExtension = null;
 31
 3832            if (assetBundle)
 33            {
 2234                assetBundle.Unload(true);
 2235                assetBundle = null;
 36            }
 3837        }
 38
 39        public List<T> GetAssetsByExtensions<T>(params string[] extensions)
 40            where T : Object
 41        {
 1542            var goList = new List<T>();
 43
 9044            for (int i1 = 0; i1 < extensions.Length; i1++)
 45            {
 3046                string ext = extensions[i1];
 47                List<Object> assets;
 48
 3049                if (assetsByExtension.ContainsKey(ext))
 50                {
 1351                    assets = assetsByExtension[ext];
 1352                    int glbCount = assets.Count;
 53
 5254                    for (int i = 0; i < glbCount; i++)
 55                    {
 1356                        Object go = assets[i];
 57
 1358                        if (go is T)
 1359                            goList.Add((T) go);
 60                    }
 61                }
 62            }
 63
 1564            return goList;
 65        }
 66        public void AddAssetByExtension(string ext, Object loadedAsset)
 67        {
 7268            if (assetsByExtension == null)
 69            {
 070                Debug.LogWarning($"Trying to add asset of type {ext} to unloaded AB");
 71
 072                return;
 73            }
 74
 7275            if (!assetsByExtension.ContainsKey(ext))
 76            {
 5377                assetsByExtension.Add(ext, new List<Object>());
 78            }
 79
 7280            assetsByExtension[ext].Add(loadedAsset);
 7281        }
 82        public void SetAssetBundle(AssetBundle ab)
 83        {
 2284            assetBundle = ab;
 2285        }
 86
 87        public void LoadMetrics()
 88        {
 2289            var metricsFile = assetBundle.LoadAsset<TextAsset>(METRICS_FILENAME);
 2290            if (metricsFile != null)
 091                metrics = JsonUtility.FromJson<AssetBundleMetrics>(metricsFile.text);
 2292        }
 93
 94        public TextAsset GetMetadata()
 95        {
 096            return GetMetadata(assetBundle);
 97        }
 98        public AssetBundleRequest LoadAllAssetsAsync()
 99        {
 22100            return assetBundle.LoadAllAssetsAsync();
 101        }
 102
 103        public static TextAsset GetMetadata(AssetBundle assetBundle)
 104        {
 22105            return assetBundle.LoadAsset<TextAsset>(METADATA_FILENAME);
 106        }
 107    }
 108}