< 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:94
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.Linq;
 2using DCL.Helpers;
 3using DCL.Models;
 4using UnityEngine;
 5
 6namespace DCL.Components
 7{
 8    public class LoadWrapper_NFT : LoadWrapper
 9    {
 10        public NFTShapeLoaderController loaderController;
 11
 12        public bool withCollisions;
 13        public Color backgroundColor;
 14
 15        private string assetUrl;
 16        private Rendereable rendereable;
 17
 18        public override void Unload()
 19        {
 820            CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChanged;
 821            loaderController.OnLoadingAssetSuccess -= OnLoadingAssetSuccess;
 22
 823            Object.Destroy(loaderController);
 24
 825            Utils.SafeDestroy(entity.meshRootGameObject);
 826            entity.meshesInfo.CleanReferences();
 27
 828            DataStore.i.sceneWorldObjects.RemoveRendereable(entity, rendereable);
 829        }
 30
 31        public override void Load(string src, System.Action<LoadWrapper> OnSuccess, System.Action<LoadWrapper> OnFail)
 32        {
 1033            if (string.IsNullOrEmpty(src))
 034                return;
 35
 1036            if (loaderController == null)
 1037                loaderController = entity.meshRootGameObject.GetComponent<NFTShapeLoaderController>();
 38
 1039            if (loaderController == null)
 40            {
 041                Debug.LogError("LoadWrapper_NFT >>> loaderController == null!");
 042                return;
 43            }
 44
 1045            loaderController.collider.enabled = withCollisions;
 1046            loaderController.backgroundColor = backgroundColor;
 47
 1048            loaderController.OnLoadingAssetSuccess += OnLoadingAssetSuccess;
 49
 1050            assetUrl = src;
 51
 1052            if (CommonScriptableObjects.rendererState.Get())
 53            {
 1054                LoadAsset();
 1055            }
 56            else
 57            {
 058                CommonScriptableObjects.rendererState.OnChange += OnRendererStateChanged;
 59            }
 60
 61            // NOTE: frame meshes are already included in the build, there is no need lock renderer just to wait for the
 1062            OnSuccess?.Invoke(this);
 1063        }
 64
 65        void OnLoadingAssetSuccess()
 66        {
 1467            if (alreadyLoaded)
 768                return;
 69
 770            alreadyLoaded = true;
 71
 772            rendereable = Rendereable.CreateFromGameObject(entity.meshRootGameObject);
 773            DataStore.i.sceneWorldObjects.AddRendereable(entity, rendereable);
 74
 775            entity.OnShapeUpdated?.Invoke(entity);
 776            entity.OnShapeLoaded?.Invoke(entity);
 077        }
 78
 79        void LoadAsset()
 80        {
 1081            if ( loaderController != null )
 1082                loaderController.LoadAsset(assetUrl, true);
 1083        }
 84
 85        void OnRendererStateChanged(bool current, bool previous)
 86        {
 087            if (current)
 88            {
 089                CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChanged;
 090                LoadAsset();
 91            }
 092        }
 93    }
 94}