< Summary

Class:DCL.Components.LoadWrapper_GLTF
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/LoadWrapper/LoadWrapper_GLTF.cs
Covered lines:43
Uncovered lines:5
Coverable lines:48
Total lines:101
Line coverage:89.5% (43 of 48)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Load(...)0%6.156084%
OnFailWrapper(...)0%220100%
OnSuccessWrapper(...)0%220100%
OnEntityCleanup(...)0%110100%
Unload()0%220100%
ToString()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/LoadWrapper/LoadWrapper_GLTF.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3using UnityEngine.Assertions;
 4
 5namespace DCL.Components
 6{
 7    public class LoadWrapper_GLTF : LoadWrapper
 8    {
 9        static readonly bool VERBOSE = false;
 10
 11        RendereableAssetLoadHelper loadHelper;
 12
 13        public ContentProvider customContentProvider;
 14
 15        private Action<Rendereable> successWrapperEvent;
 16        private Action<Exception> failWrapperEvent;
 17
 18        public override void Load(string targetUrl, Action<LoadWrapper> OnSuccess, Action<LoadWrapper, Exception> OnFail
 19        {
 8920            if (loadHelper != null)
 21            {
 222                loadHelper.Unload();
 23
 224                if (VERBOSE)
 025                    Debug.Log("Forgetting not null loader...");
 26            }
 27
 8928            alreadyLoaded = false;
 8929            Assert.IsFalse(string.IsNullOrEmpty(targetUrl), "url is null!!");
 30
 31
 8932            if (customContentProvider == null)
 033                loadHelper = new RendereableAssetLoadHelper(this.entity.scene.contentProvider, entity.scene.sceneData.ba
 34            else
 8935                loadHelper = new RendereableAssetLoadHelper(customContentProvider, entity.scene.sceneData.baseUrlBundles
 36
 8937            loadHelper.settings.forceGPUOnlyMesh = true;
 8938            loadHelper.settings.parent = entity.meshRootGameObject.transform;
 39
 8940            if (initialVisibility == false)
 41            {
 042                loadHelper.settings.visibleFlags = AssetPromiseSettings_Rendering.VisibleFlags.INVISIBLE;
 043            }
 44            else
 45            {
 8946                if (useVisualFeedback)
 147                    loadHelper.settings.visibleFlags = AssetPromiseSettings_Rendering.VisibleFlags.VISIBLE_WITH_TRANSITI
 48                else
 8849                    loadHelper.settings.visibleFlags = AssetPromiseSettings_Rendering.VisibleFlags.VISIBLE_WITHOUT_TRANS
 50            }
 51
 8952            this.entity.OnCleanupEvent -= OnEntityCleanup;
 8953            this.entity.OnCleanupEvent += OnEntityCleanup;
 54
 15755            successWrapperEvent = x => OnSuccessWrapper(OnSuccess);
 9256            failWrapperEvent = error => OnFailWrapper(OnFail, error);
 57
 8958            loadHelper.OnSuccessEvent += successWrapperEvent;
 8959            loadHelper.OnFailEvent += failWrapperEvent;
 8960            loadHelper.Load(targetUrl);
 8961        }
 62
 63        private void OnFailWrapper(Action<LoadWrapper, Exception> OnFail, Exception exception)
 64        {
 365            alreadyLoaded = true;
 366            loadHelper.OnSuccessEvent -= successWrapperEvent;
 367            loadHelper.OnFailEvent -= failWrapperEvent;
 368            this.entity.OnCleanupEvent -= OnEntityCleanup;
 369            OnFail?.Invoke(this, exception);
 370        }
 71
 72        private void OnSuccessWrapper(Action<LoadWrapper> OnSuccess)
 73        {
 6874            alreadyLoaded = true;
 6875            loadHelper.OnSuccessEvent -= successWrapperEvent;
 6876            loadHelper.OnFailEvent -= failWrapperEvent;
 77
 6878            loadHelper.loadedAsset.ownerId = entity.entityId;
 6879            DataStore.i.sceneWorldObjects.AddRendereable(entity.scene.sceneData.id, loadHelper.loadedAsset);
 6880            OnSuccess?.Invoke(this);
 6881        }
 82
 283        public void OnEntityCleanup(ICleanableEventDispatcher source) { Unload(); }
 84
 85        public override void Unload()
 86        {
 2087            if ( loadHelper.loadedAsset != null )
 88            {
 1589                DataStore.i.sceneWorldObjects.RemoveRendereable(entity.scene.sceneData.id, loadHelper.loadedAsset);
 90            }
 91
 2092            loadHelper.Unload();
 2093            this.entity.OnCleanupEvent -= OnEntityCleanup;
 2094            loadHelper.OnSuccessEvent -= successWrapperEvent;
 2095            loadHelper.OnFailEvent -= failWrapperEvent;
 2096            alreadyLoaded = false;
 2097        }
 98
 099        public override string ToString() { return $"LoadWrapper ... {loadHelper.ToString()}"; }
 100    }
 101}