< 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:23
Uncovered lines:8
Coverable lines:31
Total lines:78
Line coverage:74.1% (23 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%220100%
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        {
 818            CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChanged;
 819            loaderController.OnLoadingAssetSuccess -= CallOnComponentUpdated;
 820            Object.Destroy(loaderController);
 21
 822            Utils.SafeDestroy(entity.meshRootGameObject);
 823            entity.meshesInfo.CleanReferences();
 824        }
 25
 26        public override void Load(string src, System.Action<LoadWrapper> OnSuccess, System.Action<LoadWrapper> OnFail)
 27        {
 928            if (string.IsNullOrEmpty(src))
 029                return;
 30
 931            if (loaderController == null)
 932                loaderController = entity.meshRootGameObject.GetComponent<NFTShapeLoaderController>();
 33
 934            if (loaderController == null)
 35            {
 036                Debug.LogError("LoadWrapper_NFT >>> loaderController == null!");
 037                return;
 38            }
 39
 940            loaderController.collider.enabled = withCollisions;
 941            loaderController.backgroundColor = backgroundColor;
 42
 943            loaderController.OnLoadingAssetSuccess += CallOnComponentUpdated;
 44
 945            assetUrl = src;
 46
 947            if (CommonScriptableObjects.rendererState.Get())
 48            {
 949                LoadAsset();
 950            }
 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
 957            OnSuccess?.Invoke(this);
 958        }
 59
 60        void CallOnComponentUpdated()
 61        {
 1262            alreadyLoaded = true;
 63
 1264            entity.OnShapeUpdated?.Invoke(entity);
 1265        }
 66
 1867        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}