< Summary

Class:DCL.Components.LoadWrapper_NFT
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/LoadWrapper/LoadWrapper_NFT.cs
Covered lines:20
Uncovered lines:11
Coverable lines:31
Total lines:78
Line coverage:64.5% (20 of 31)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Unload()0%110100%
Load(...)0%6.476076.47%
CallOnComponentUpdated()0%6200%
LoadAsset()0%220100%
OnRendererStateChanged(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/LoadWrapper/LoadWrapper_NFT.cs

#LineLine coverage
 1using DCL.Helpers;
 2using UnityEngine;
 3
 4namespace DCL.Components
 5{
 6    public class LoadWrapper_NFT : LoadWrapper
 7    {
 8        [HideInInspector] public NFTShapeLoaderController loaderController;
 9
 10        public bool withCollisions;
 11        public Color backgroundColor;
 12        public BaseDisposable component;
 13
 14        string assetUrl;
 15
 16        public override void Unload()
 17        {
 118            CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChanged;
 119            loaderController.OnLoadingAssetSuccess -= CallOnComponentUpdated;
 120            Object.Destroy(loaderController);
 21
 122            Utils.SafeDestroy(entity.meshRootGameObject);
 123            entity.meshesInfo.CleanReferences();
 124        }
 25
 26        public override void Load(string src, System.Action<LoadWrapper> OnSuccess, System.Action<LoadWrapper> OnFail)
 27        {
 228            if (string.IsNullOrEmpty(src))
 029                return;
 30
 231            if (loaderController == null)
 232                loaderController = entity.meshRootGameObject.GetComponent<NFTShapeLoaderController>();
 33
 234            if (loaderController == null)
 35            {
 036                Debug.LogError("LoadWrapper_NFT >>> loaderController == null!");
 037                return;
 38            }
 39
 240            loaderController.collider.enabled = withCollisions;
 241            loaderController.backgroundColor = backgroundColor;
 42
 243            loaderController.OnLoadingAssetSuccess += CallOnComponentUpdated;
 44
 245            assetUrl = src;
 46
 247            if (CommonScriptableObjects.rendererState.Get())
 48            {
 249                LoadAsset();
 250            }
 51            else
 52            {
 053                CommonScriptableObjects.rendererState.OnChange += OnRendererStateChanged;
 54            }
 55
 56            // NOTE: frame meshes are already included in the build, there is no need lock renderer just to wait for the
 257            OnSuccess?.Invoke(this);
 258        }
 59
 60        void CallOnComponentUpdated()
 61        {
 062            alreadyLoaded = true;
 63
 064            entity.OnShapeUpdated?.Invoke(entity);
 065        }
 66
 467        void LoadAsset() { loaderController?.LoadAsset(assetUrl, true); }
 68
 69        void OnRendererStateChanged(bool current, bool previous)
 70        {
 071            if (current)
 72            {
 073                CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChanged;
 074                LoadAsset();
 75            }
 076        }
 77    }
 78}