< Summary

Class:ThumbnailsManager
Assembly:ThumbnailsManager
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/ThumbnailsManager/ThumbnailsManager.cs
Covered lines:16
Uncovered lines:8
Coverable lines:24
Total lines:63
Line coverage:66.6% (16 of 24)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ThumbnailsManager()0%110100%
PreloadThumbnail(...)0%6.283028.57%
ForgetThumbnail(...)0%220100%
GetThumbnail(...)0%3.013088.89%
CreateSpriteFromTexture(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/ThumbnailsManager/ThumbnailsManager.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using UnityEngine;
 5using UnityEngine.Networking;
 6using DCL;
 7
 8//In the future the AssetManager will do this
 9public static class ThumbnailsManager
 10{
 11#if UNITY_EDITOR
 112    public static bool bypassRequests = false;
 13#endif
 114    static Dictionary<string, Sprite> loadedSprites = new Dictionary<string, Sprite>();
 15
 16    public static AssetPromise_Texture PreloadThumbnail(string url)
 17    {
 18#if UNITY_EDITOR
 419        if (bypassRequests)
 420            return null;
 21#endif
 022        if (string.IsNullOrEmpty(url))
 023            return null;
 24
 025        var promise = new AssetPromise_Texture(url);
 026        AssetPromiseKeeper_Texture.i.Keep(promise);
 27
 028        return promise;
 29    }
 30
 31    public static void ForgetThumbnail(AssetPromise_Texture promise)
 32    {
 39633        if (promise == null)
 20634            return;
 35
 36        //Debug.Log("Forget thumbnail " + promise.asset.id);
 19037        AssetPromiseKeeper_Texture.i.Forget(promise);
 19038    }
 39
 40    public static AssetPromise_Texture GetThumbnail(string url, Action<Asset_Texture> OnComplete)
 41    {
 42#if UNITY_EDITOR
 19843        if (bypassRequests)
 844            return null;
 45#endif
 19046        if (string.IsNullOrEmpty(url))
 047            return null;
 48
 19049        var promise = new AssetPromise_Texture(url);
 50
 19051        promise.OnSuccessEvent += OnComplete;
 19052        promise.OnFailEvent += (x, error) => { Debug.Log($"Error downloading: {url}, Exception: {error}"); };
 53
 19054        AssetPromiseKeeper_Texture.i.Keep(promise);
 19055        return promise;
 56    }
 57
 58    public static Sprite CreateSpriteFromTexture(Texture2D texture)
 59    {
 060        var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
 061        return sprite;
 62    }
 63}