< Summary

Class:MainScripts.DCL.Controllers.AssetManager.Addressables.Editor.EditorAddressableResourceProvider
Assembly:AddressableResourceProviderEditor
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/Addressables/Editor/EditorAddressableResourceProvider.cs
Covered lines:0
Uncovered lines:25
Coverable lines:25
Total lines:70
Line coverage:0% (0 of 25)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:6
Method coverage:0% (0 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetAddressablesList[T](...)0%2100%
GetAddressable[T](...)0%12300%
Instantiate[T](...)0%12300%
EnsureInitializedSync()0%2100%
Dispose()0%2100%
Initialize()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/Addressables/Editor/EditorAddressableResourceProvider.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL.Providers;
 3using System.Collections.Generic;
 4using System.Threading;
 5using UnityEngine;
 6using UnityEngine.AddressableAssets;
 7using UnityEngine.ResourceManagement.AsyncOperations;
 8
 9namespace MainScripts.DCL.Controllers.AssetManager.Addressables.Editor
 10{
 11    /// <summary>
 12    /// <see cref="AddressableResourceProvider"/> does not advance the UniTask if not in the play mode.
 13    /// it is a synchronous replacements to operates from Unit tests fully synchronously
 14    /// </summary>
 15    public class EditorAddressableResourceProvider : IAddressableResourceProvider
 16    {
 17        public UniTask<IList<T>> GetAddressablesList<T>(string key, CancellationToken cancellationToken = default)
 18        {
 019            EnsureInitializedSync();
 020            var r = UnityEngine.AddressableAssets.Addressables.LoadAssetsAsync<T>(key, null).WaitForCompletion();
 021            return UniTask.FromResult(r);
 22        }
 23
 24        public UniTask<T> GetAddressable<T>(string key, CancellationToken cancellationToken = default)
 25        {
 026            EnsureInitializedSync();
 27
 028            if (typeof(Component).IsAssignableFrom(typeof(T)))
 29            {
 30                // load as GameObject instead as it is the root type
 031                var goRequest = UnityEngine.AddressableAssets.Addressables.LoadAssetAsync<GameObject>(key);
 032                goRequest.WaitForCompletion();
 33
 034                var component = goRequest.Result.GetComponent<T>();
 35
 036                if (component == null)
 037                    throw new InvalidKeyException($"GameObject {key} does not contain the component of the requested typ
 38
 039                return UniTask.FromResult(component);
 40            }
 41
 042            AsyncOperationHandle<T> request = UnityEngine.AddressableAssets.Addressables.LoadAssetAsync<T>(key);
 043            request.WaitForCompletion();
 044            return UniTask.FromResult(request.Result);
 45        }
 46
 47        public UniTask<T> Instantiate<T>(string address, string name = "", Transform parent = null, CancellationToken ca
 48        {
 049            EnsureInitializedSync();
 50
 051            var request = UnityEngine.AddressableAssets.Addressables.InstantiateAsync(address, parent);
 052            request.WaitForCompletion();
 53
 054            if (Application.isEditor && name != default(string))
 055                request.Result.name = name;
 56
 057            return UniTask.FromResult(request.Result.GetComponent<T>());
 58        }
 59
 60        private void EnsureInitializedSync()
 61        {
 062            var init = UnityEngine.AddressableAssets.Addressables.InitializeAsync();
 063            init.WaitForCompletion();
 064        }
 65
 066        public void Dispose() { }
 67
 068        public void Initialize() { }
 69    }
 70}