< 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:30
Uncovered lines:9
Coverable lines:39
Total lines:96
Line coverage:76.9% (30 of 39)
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%
OnLoadingAssetSuccess()0%4.034087.5%
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 System;
 2using System.Linq;
 3using DCL.Helpers;
 4using DCL.Models;
 5using UnityEngine;
 6using Object = UnityEngine.Object;
 7
 8namespace DCL.Components
 9{
 10    public class LoadWrapper_NFT : LoadWrapper
 11    {
 12        public NFTShapeLoaderController loaderController;
 13
 14        public bool withCollisions;
 15        public Color backgroundColor;
 16
 17        private string assetUrl;
 18        private Rendereable rendereable;
 19
 20        public override void Unload()
 21        {
 822            CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChanged;
 823            loaderController.OnLoadingAssetSuccess -= OnLoadingAssetSuccess;
 24
 825            Object.Destroy(loaderController);
 26
 827            Utils.SafeDestroy(entity.meshRootGameObject);
 828            entity.meshesInfo.CleanReferences();
 29
 830            DataStore.i.sceneWorldObjects.RemoveRendereable(entity, rendereable);
 831        }
 32
 33        public override void Load(string src, System.Action<LoadWrapper> OnSuccess, System.Action<LoadWrapper, Exception
 34        {
 1035            if (string.IsNullOrEmpty(src))
 036                return;
 37
 1038            if (loaderController == null)
 1039                loaderController = entity.meshRootGameObject.GetComponent<NFTShapeLoaderController>();
 40
 1041            if (loaderController == null)
 42            {
 043                Debug.LogError("LoadWrapper_NFT >>> loaderController == null!");
 044                return;
 45            }
 46
 1047            loaderController.collider.enabled = withCollisions;
 1048            loaderController.backgroundColor = backgroundColor;
 49
 1050            loaderController.OnLoadingAssetSuccess += OnLoadingAssetSuccess;
 51
 1052            assetUrl = src;
 53
 1054            if (CommonScriptableObjects.rendererState.Get())
 55            {
 1056                LoadAsset();
 1057            }
 58            else
 59            {
 060                CommonScriptableObjects.rendererState.OnChange += OnRendererStateChanged;
 61            }
 62
 63            // NOTE: frame meshes are already included in the build, there is no need lock renderer just to wait for the
 1064            OnSuccess?.Invoke(this);
 1065        }
 66
 67        void OnLoadingAssetSuccess()
 68        {
 1469            if (alreadyLoaded)
 770                return;
 71
 772            alreadyLoaded = true;
 73
 774            rendereable = Rendereable.CreateFromGameObject(entity.meshRootGameObject);
 775            DataStore.i.sceneWorldObjects.AddRendereable(entity, rendereable);
 76
 777            entity.OnShapeUpdated?.Invoke(entity);
 778            entity.OnShapeLoaded?.Invoke(entity);
 079        }
 80
 81        void LoadAsset()
 82        {
 1083            if ( loaderController != null )
 1084                loaderController.LoadAsset(assetUrl, true);
 1085        }
 86
 87        void OnRendererStateChanged(bool current, bool previous)
 88        {
 089            if (current)
 90            {
 091                CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChanged;
 092                LoadAsset();
 93            }
 094        }
 95    }
 96}