< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Unload()0%330100%
Load(...)0%6.566075%
OnLoadingAssetSuccess()0%4.184077.78%
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        {
 622            CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChanged;
 623            if (loaderController != null)
 24            {
 625                loaderController.OnLoadingAssetSuccess -= OnLoadingAssetSuccess;
 626                Object.Destroy(loaderController);
 27            }
 28
 629            if(entity.meshRootGameObject != null)
 630                Utils.SafeDestroy(entity.meshRootGameObject);
 31
 632            entity.meshesInfo.CleanReferences();
 33
 634            DataStore.i.sceneWorldObjects.RemoveRendereable(entity.scene.sceneData.sceneNumber, rendereable);
 635        }
 36
 37        public override void Load(string src, System.Action<LoadWrapper> OnSuccess, System.Action<LoadWrapper, Exception
 38        {
 739            if (string.IsNullOrEmpty(src))
 040                return;
 41
 742            if (loaderController == null)
 743                loaderController = entity.meshRootGameObject.GetComponent<NFTShapeLoaderController>();
 44
 745            if (loaderController == null)
 46            {
 047                Debug.LogError("LoadWrapper_NFT >>> loaderController == null!");
 048                return;
 49            }
 50
 751            loaderController.collider.enabled = withCollisions;
 752            loaderController.backgroundColor = backgroundColor;
 53
 754            loaderController.OnLoadingAssetSuccess += OnLoadingAssetSuccess;
 55
 756            assetUrl = src;
 57
 758            if (CommonScriptableObjects.rendererState.Get())
 59            {
 760                LoadAsset();
 61            }
 62            else
 63            {
 064                CommonScriptableObjects.rendererState.OnChange += OnRendererStateChanged;
 65            }
 66
 67            // NOTE: frame meshes are already included in the build, there is no need lock renderer just to wait for the
 768            OnSuccess?.Invoke(this);
 769        }
 70
 71        void OnLoadingAssetSuccess()
 72        {
 773            if (alreadyLoaded)
 074                return;
 75
 776            alreadyLoaded = true;
 77
 778            rendereable = Rendereable.CreateFromGameObject(entity.meshRootGameObject);
 779            rendereable.ownerId = entity.entityId;
 780            DataStore.i.sceneWorldObjects.AddRendereable(entity.scene.sceneData.sceneNumber, rendereable);
 81
 782            entity.OnShapeUpdated?.Invoke(entity);
 783            entity.OnShapeLoaded?.Invoke(entity);
 084        }
 85
 86        void LoadAsset()
 87        {
 788            if ( loaderController != null )
 789                loaderController.LoadAsset(assetUrl, true);
 790        }
 91
 92        void OnRendererStateChanged(bool current, bool previous)
 93        {
 094            if (current)
 95            {
 096                CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChanged;
 097                LoadAsset();
 98            }
 099        }
 100    }
 101}