< Summary

Class:DCL.AssetPromise_GLTF
Assembly:AssetPromiseKeeper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/GLTF/AssetPromise_GLTF.cs
Covered lines:39
Uncovered lines:2
Coverable lines:41
Total lines:113
Line coverage:95.1% (39 of 41)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AssetPromise_GLTF(...)0%220100%
OnBeforeLoadOrReuse()0%330100%
OnAfterLoadOrReuse()0%110100%
GetId()0%110100%
OnLoad(...)0%110100%
ParseGLTFWebRequestedFile(...)0%110100%
OnReuse(...)0%110100%
AddToLibrary()0%4.024090%
OnCancelLoading()0%220100%
GetAsset(...)0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/GLTF/AssetPromise_GLTF.cs

#LineLine coverage
 1using DCL.Helpers;
 2using UnityGLTF;
 3
 4namespace DCL
 5{
 6    public class AssetPromise_GLTF : AssetPromise<Asset_GLTF>
 7    {
 1228        public AssetPromiseSettings_Rendering settings = new AssetPromiseSettings_Rendering();
 9        protected string assetDirectoryPath;
 10
 11        protected ContentProvider provider = null;
 012        public string url { get; private set; }
 13
 14        GLTFComponent gltfComponent = null;
 15        object id = null;
 16
 12217        public AssetPromise_GLTF(ContentProvider provider, string url, string hash = null)
 18        {
 12219            this.provider = provider;
 12220            this.url = url.Substring(url.LastIndexOf('/') + 1);
 12221            this.id = hash ?? url;
 22            // We separate the directory path of the GLB and its file name, to be able to use the directory path when
 23            // fetching relative assets like textures in the ParseGLTFWebRequestedFile() event call
 12224            assetDirectoryPath = URIHelper.GetDirectoryName(url);
 12225        }
 26
 27        protected override void OnBeforeLoadOrReuse()
 28        {
 29#if UNITY_EDITOR
 16930            asset.container.name = "GLTF: " + this.id;
 31#endif
 16932            settings.ApplyBeforeLoad(asset.container.transform);
 16933        }
 34
 16835        protected override void OnAfterLoadOrReuse() { settings.ApplyAfterLoad(asset.container.transform); }
 36
 73237        public override object GetId() { return id; }
 38
 39        protected override void OnLoad(System.Action OnSuccess, System.Action OnFail)
 40        {
 8541            gltfComponent = asset.container.AddComponent<GLTFComponent>();
 8542            gltfComponent.Initialize(DCL.Environment.i.platform.webRequest);
 43
 8544            GLTFComponent.Settings tmpSettings = new GLTFComponent.Settings()
 45            {
 46                useVisualFeedback = settings.visibleFlags == AssetPromiseSettings_Rendering.VisibleFlags.VISIBLE_WITH_TR
 47                initialVisibility = settings.visibleFlags != AssetPromiseSettings_Rendering.VisibleFlags.INVISIBLE,
 48                shaderOverride = settings.shaderOverride,
 49                addMaterialsToPersistentCaching = (settings.cachingFlags & MaterialCachingHelper.Mode.CACHE_MATERIALS) !
 50            };
 51
 8552            tmpSettings.OnWebRequestStartEvent += ParseGLTFWebRequestedFile;
 53
 8554            gltfComponent.LoadAsset(url, GetId() as string, false, tmpSettings);
 8555            gltfComponent.OnSuccess += OnSuccess;
 8556            gltfComponent.OnFail += OnFail;
 57
 8558            asset.name = url;
 8559        }
 60
 18861        void ParseGLTFWebRequestedFile(ref string requestedFileName) { provider.TryGetContentsUrl(assetDirectoryPath + r
 62
 63        protected override void OnReuse(System.Action OnSuccess)
 64        {
 65            //NOTE(Brian):  Show the asset using the simple gradient feedback.
 2666            asset.Show(settings.visibleFlags == AssetPromiseSettings_Rendering.VisibleFlags.VISIBLE_WITH_TRANSITION, OnS
 2667        }
 68
 69        protected override bool AddToLibrary()
 70        {
 6071            if (!library.Add(asset))
 072                return false;
 73
 6074            if (!asset.visible)
 275                return true;
 76
 77            //NOTE(Brian): If the asset did load "in world" add it to library and then Get it immediately
 78            //             So it keeps being there. As master gltfs can't be in the world.
 79            //
 80            //             ApplySettings will reposition the newly Get asset to the proper coordinates.
 5881            if (settings.forceNewInstance)
 82            {
 283                asset = (library as AssetLibrary_GLTF).GetCopyFromOriginal(asset.id);
 284            }
 85            else
 86            {
 5687                asset = library.Get(asset.id);
 88            }
 89
 90            //NOTE(Brian): Call again this method because we are replacing the asset.
 5891            OnBeforeLoadOrReuse();
 5892            return true;
 93        }
 94
 95        protected override void OnCancelLoading()
 96        {
 2797            if (asset != null)
 2798                asset.CancelShow();
 2799        }
 100
 101        protected override Asset_GLTF GetAsset(object id)
 102        {
 26103            if (settings.forceNewInstance)
 104            {
 9105                return ((AssetLibrary_GLTF) library).GetCopyFromOriginal(id);
 106            }
 107            else
 108            {
 17109                return base.GetAsset(id);
 110            }
 111        }
 112    }
 113}