< Summary

Class:AvatarSystem.WearableRetriever
Assembly:AvatarSystem
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/AvatarSystem/Loader/WearableRetriever.cs
Covered lines:28
Uncovered lines:7
Coverable lines:35
Total lines:77
Line coverage:80% (28 of 35)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Retrieve()0%9.049092.31%
Dispose()0%220100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Threading;
 3using Cysharp.Threading.Tasks;
 4using DCL;
 5using DCL.Components;
 6using DCL.Helpers;
 7using UnityEngine;
 8
 9namespace AvatarSystem
 10{
 11    public class WearableRetriever : IWearableRetriever
 12    {
 2413        public Rendereable rendereable { get; private set; }
 14
 15        private RendereableAssetLoadHelper loaderAssetHelper;
 16
 17        public async UniTask<Rendereable> Retrieve(GameObject container, ContentProvider contentProvider, string baseUrl
 18        {
 8419            ct.ThrowIfCancellationRequested();
 20
 21            try
 22            {
 8423                loaderAssetHelper?.Unload();
 24
 8425                loaderAssetHelper = new RendereableAssetLoadHelper(contentProvider, baseUrl);
 26
 8427                loaderAssetHelper.settings.forceNewInstance = false;
 28                // TODO Review this hardcoded offset and try to solve it by offseting the Avatar container
 8429                loaderAssetHelper.settings.initialLocalPosition = Vector3.up * AvatarSystemUtils.AVATAR_Y_OFFSET;
 8430                loaderAssetHelper.settings.cachingFlags = MaterialCachingHelper.Mode.CACHE_SHADERS;
 8431                loaderAssetHelper.settings.visibleFlags = AssetPromiseSettings_Rendering.VisibleFlags.INVISIBLE;
 8432                loaderAssetHelper.settings.parent = container.transform;
 8433                loaderAssetHelper.settings.layer = container.layer;
 34
 8435                bool done = false;
 8436                Exception exception = null;
 37
 38                void OnSuccessWrapper(Rendereable rendereable)
 39                {
 840                    loaderAssetHelper?.ClearEvents();
 841                    done = true;
 842                    this.rendereable = rendereable;
 843                }
 44
 45                void OnFailEventWrapper(Exception e)
 46                {
 047                    exception = e;
 048                    loaderAssetHelper?.ClearEvents();
 049                    done = true;
 050                    rendereable = null;
 051                }
 52
 8453                loaderAssetHelper.OnSuccessEvent += OnSuccessWrapper;
 8454                loaderAssetHelper.OnFailEvent += OnFailEventWrapper;
 8455                loaderAssetHelper.Load(mainFile, AvatarSystemUtils.UseAssetBundles() ? RendereableAssetLoadHelper.Loadin
 56
 57                // AttachExternalCancellation is needed because a cancelled WaitUntil UniTask requires a frame
 33758                await UniTask.WaitUntil(() => done, cancellationToken: ct).AttachExternalCancellation(ct);
 59
 860                if (exception != null)
 061                    throw exception;
 62
 863                if (rendereable == null)
 064                    throw new Exception($"Couldnt retrieve Wearable assets at: {mainFile}");
 65
 866                return rendereable;
 67            }
 7668            catch (OperationCanceledException e)
 69            {
 7670                Dispose();
 7671                throw;
 72            }
 873        }
 74
 82775        public void Dispose() { loaderAssetHelper?.Unload(); }
 76    }
 77}