< 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:16
Uncovered lines:24
Coverable lines:40
Total lines:97
Line coverage:40% (16 of 40)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Unload()0%2100%
Load(...)0%6.476076.47%
OnLoadingAssetSuccess()0%20400%
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        {
 022            CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChanged;
 023            loaderController.OnLoadingAssetSuccess -= OnLoadingAssetSuccess;
 24
 025            Object.Destroy(loaderController);
 26
 027            Utils.SafeDestroy(entity.meshRootGameObject);
 028            entity.meshesInfo.CleanReferences();
 29
 030            DataStore.i.sceneWorldObjects.RemoveRendereable(entity.scene.sceneData.id, rendereable);
 031        }
 32
 33        public override void Load(string src, System.Action<LoadWrapper> OnSuccess, System.Action<LoadWrapper, Exception
 34        {
 335            if (string.IsNullOrEmpty(src))
 036                return;
 37
 338            if (loaderController == null)
 339                loaderController = entity.meshRootGameObject.GetComponent<NFTShapeLoaderController>();
 40
 341            if (loaderController == null)
 42            {
 043                Debug.LogError("LoadWrapper_NFT >>> loaderController == null!");
 044                return;
 45            }
 46
 347            loaderController.collider.enabled = withCollisions;
 348            loaderController.backgroundColor = backgroundColor;
 49
 350            loaderController.OnLoadingAssetSuccess += OnLoadingAssetSuccess;
 51
 352            assetUrl = src;
 53
 354            if (CommonScriptableObjects.rendererState.Get())
 55            {
 356                LoadAsset();
 357            }
 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
 364            OnSuccess?.Invoke(this);
 365        }
 66
 67        void OnLoadingAssetSuccess()
 68        {
 069            if (alreadyLoaded)
 070                return;
 71
 072            alreadyLoaded = true;
 73
 074            rendereable = Rendereable.CreateFromGameObject(entity.meshRootGameObject);
 075            rendereable.ownerId = entity.entityId;
 076            DataStore.i.sceneWorldObjects.AddRendereable(entity.scene.sceneData.id, rendereable);
 77
 078            entity.OnShapeUpdated?.Invoke(entity);
 079            entity.OnShapeLoaded?.Invoke(entity);
 080        }
 81
 82        void LoadAsset()
 83        {
 384            if ( loaderController != null )
 385                loaderController.LoadAsset(assetUrl, true);
 386        }
 87
 88        void OnRendererStateChanged(bool current, bool previous)
 89        {
 090            if (current)
 91            {
 092                CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChanged;
 093                LoadAsset();
 94            }
 095        }
 96    }
 97}