< Summary

Class:DCL.Helpers.TextureLoader
Assembly:LazyTextureObserver
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/LazyTextureObserver/TextureLoader.cs
Covered lines:2
Uncovered lines:14
Coverable lines:16
Total lines:44
Line coverage:12.5% (2 of 16)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetTexture()0%2100%
Load(...)0%6200%
Unload()0%2.152066.67%

File(s)

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

#LineLine coverage
 1using System;
 2using UnityEngine;
 3
 4namespace DCL.Helpers
 5{
 6    internal class TextureLoader : ITextureLoader
 7    {
 8        private AssetPromise_Texture currentPromise;
 9        public event Action<Texture2D> OnSuccess;
 10        public event Action OnFail;
 11
 12        public Texture2D GetTexture()
 13        {
 014            return currentPromise.asset.texture;
 15        }
 16
 17        public void Load(string uri)
 18        {
 019            if ( currentPromise != null )
 020                AssetPromiseKeeper_Texture.i.Forget(currentPromise);
 21
 022            currentPromise = new AssetPromise_Texture(uri);
 23
 024            currentPromise.OnSuccessEvent += (x) =>
 25            {
 026                OnSuccess?.Invoke(x.texture);
 027            };
 28
 029            currentPromise.OnFailEvent += (x) =>
 30            {
 031                OnFail?.Invoke();
 032                Debug.LogError($"Texture loading failed! {uri}");
 033            };
 34
 035            AssetPromiseKeeper_Texture.i.Keep(currentPromise);
 036        }
 37
 38        public void Unload()
 39        {
 12140            if ( currentPromise != null )
 041                AssetPromiseKeeper_Texture.i.Forget(currentPromise);
 12142        }
 43    }
 44}