< Summary

Class:AvatarSystem.FacialFeatureRetriever
Assembly:AvatarSystem
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/AvatarSystem/Loader/FacialFeatureRetriever.cs
Covered lines:3
Uncovered lines:39
Coverable lines:42
Total lines:86
Line coverage:7.1% (3 of 42)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Retrieve()0%1561200%
Dispose()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/AvatarSystem/Loader/FacialFeatureRetriever.cs

#LineLine coverage
 1using System;
 2using System.Threading;
 3using Cysharp.Threading.Tasks;
 4using DCL;
 5using UnityEngine;
 6
 7namespace AvatarSystem
 8{
 9    public class FacialFeatureRetriever : IFacialFeatureRetriever
 10    {
 11        AssetPromise_Texture mainTexturePromise = null;
 12        AssetPromise_Texture maskTexturePromise = null;
 13
 14        public async UniTask<(Texture main, Texture mask)> Retrieve(WearableItem facialFeature, string bodyshapeId, Canc
 15        {
 016            ct.ThrowIfCancellationRequested();
 17
 18            try
 19            {
 020                (string mainTextureUrl, string maskTextureUrl) = AvatarSystemUtils.GetFacialFeatureTexturesUrls(bodyshap
 21
 022                AssetPromiseKeeper_Texture.i.Forget(mainTexturePromise);
 023                AssetPromiseKeeper_Texture.i.Forget(maskTexturePromise);
 24
 025                Texture2D mainTexture = null;
 026                Texture2D maskTexture = null;
 027                Exception mainTextureException = null;
 028                mainTexturePromise = new AssetPromise_Texture(mainTextureUrl);
 029                mainTexturePromise.OnSuccessEvent += (x) => mainTexture = x.texture;
 030                mainTexturePromise.OnFailEvent += (x, e) =>
 31                {
 032                    mainTextureException = e;
 033                    mainTexture = null;
 034                };
 35
 036                AssetPromiseKeeper_Texture.i.Keep(mainTexturePromise);
 37
 038                Exception maskTextureException = null;
 039                if (!string.IsNullOrEmpty(maskTextureUrl))
 40                {
 041                    maskTexturePromise = new AssetPromise_Texture(maskTextureUrl);
 042                    maskTexturePromise.OnSuccessEvent += (x) => maskTexture = x.texture;
 043                    maskTexturePromise.OnFailEvent += (x, e) =>
 44                    {
 045                        maskTextureException = e;
 046                        maskTexture = null;
 047                    };
 48
 049                    AssetPromiseKeeper_Texture.i.Keep(maskTexturePromise);
 50                }
 51
 52                // AttachExternalCancellation is needed, otherwise the cancellation takes a frame to effect
 053                await mainTexturePromise.ToUniTask(cancellationToken: ct).AttachExternalCancellation(ct);
 054                if (mainTextureException != null)
 055                    throw mainTextureException;
 56
 057                if (mainTexture == null)
 058                    throw new Exception($"Couldn't fetch main texture for {facialFeature.id} at {mainTextureUrl}");
 59
 060                if (maskTexturePromise != null)
 61                {
 062                    await maskTexturePromise.ToUniTask(cancellationToken: ct).AttachExternalCancellation(ct);
 63
 064                    if (maskTextureException != null)
 065                        throw maskTextureException;
 66
 067                    if (maskTexture == null)
 068                        throw new Exception($"Couldn't fetch mask texture for {facialFeature.id} at {maskTextureUrl}");
 69                }
 70
 071                return (mainTexture, maskTexture);
 72            }
 073            catch (OperationCanceledException)
 74            {
 075                Dispose();
 076                throw;
 77            }
 078        }
 79
 80        public void Dispose()
 81        {
 86182            AssetPromiseKeeper_Texture.i.Forget(mainTexturePromise);
 86183            AssetPromiseKeeper_Texture.i.Forget(maskTexturePromise);
 86184        }
 85    }
 86}

Methods/Properties

Retrieve()
Dispose()