< Summary

Class:DCL.Asset_GLTFast_Instance
Assembly:AssetPromiseKeeper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/GLTFast/Asset_GLTFast_Instance.cs
Covered lines:32
Uncovered lines:5
Coverable lines:37
Total lines:103
Line coverage:86.4% (32 of 37)
Covered branches:0
Total branches:0
Covered methods:6
Total methods:8
Method coverage:75% (6 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Asset_GLTFast_Instance()0%110100%
ExtractRenderers()0%2100%
Cleanup()0%110100%
Hide()0%2100%
Show(...)0%220100%
ToRendereable()0%880100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/GLTFast/Asset_GLTFast_Instance.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Configuration;
 4using UnityEditor;
 5using UnityEngine;
 6using Object = UnityEngine.Object;
 7
 8namespace DCL
 9{
 10    public class Asset_GLTFast_Instance : Asset_WithPoolableContainer
 11    {
 12        internal AssetPromise_GLTFast_Loader ownerPromise;
 175813        public sealed override GameObject container { get; set; }
 14
 10415        public Asset_GLTFast_Instance()
 16        {
 10417            container = new GameObject("GLTFast Container")
 18            {
 19                transform = { position = EnvironmentSettings.MORDOR }
 20            };
 10421        }
 22
 023        public Renderer[] ExtractRenderers() => container.GetComponentsInChildren<Renderer>();
 24
 25        public override void Cleanup()
 26        {
 13227            AssetPromiseKeeper_GLTFast.i.Forget(ownerPromise);
 13228            Object.Destroy(container);
 13229        }
 30
 31        public void Hide()
 32        {
 033            container.SetActive(false);
 034            container.transform.parent = null;
 035            container.transform.position = EnvironmentSettings.MORDOR;
 036        }
 37
 38        public void Show(Action success)
 39        {
 740            container.SetActive(true);
 741            success?.Invoke();
 742        }
 43
 44        public Rendereable ToRendereable()
 45        {
 9046            Renderer[] renderers = container.gameObject.GetComponentsInChildren<Renderer>();
 9047            HashSet<Mesh> meshes = new HashSet<Mesh>();
 9048            HashSet<Material> materials = new HashSet<Material>();
 9049            HashSet<Texture> textures = new HashSet<Texture>();
 50
 9051            var tris = 0;
 49252            foreach (Renderer renderer in renderers)
 53            {
 54                switch (renderer)
 55                {
 56                    case SkinnedMeshRenderer skinnedMeshRenderer:
 2257                        Mesh skinnedMesh = skinnedMeshRenderer.sharedMesh;
 2258                        meshes.Add(skinnedMesh);
 2259                        tris += skinnedMesh.triangles.Length;
 2260                        break;
 61                    case MeshRenderer:
 13462                        Mesh mesh = renderer.GetComponent<MeshFilter>().sharedMesh;
 13463                        meshes.Add(mesh);
 13464                        tris += mesh.triangles.Length;
 65                        break;
 66                }
 67
 92468                foreach (Material material in renderer.sharedMaterials) { materials.Add(material); }
 69            }
 70
 44471            for (int i = 0; i < ownerPromise.asset.GltfImport.TextureCount; i++)
 13272                textures.Add(ownerPromise.asset.GltfImport.GetTexture(i));
 73
 9074            HashSet<AnimationClip> animations = new HashSet<AnimationClip>();
 75
 9076            var animationClips = ownerPromise.asset.GltfImport.GetAnimationClips();
 77
 9078            if (animationClips != null)
 79            {
 10080                foreach (AnimationClip clip in animationClips)
 81                {
 3182                    animations.Add(clip);
 83                }
 84            }
 85
 9086            return new Rendereable
 87            {
 88                container = container,
 89                meshes = meshes,
 90                renderers = new HashSet<Renderer>(renderers),
 91                materials = materials,
 92                textures = textures,
 93                meshToTriangleCount = new Dictionary<Mesh, int>(),
 94                animationClips = animations,
 95
 96                // TODO: Fill me!
 97                totalTriangleCount = tris,
 98                animationClipSize = 0,
 99                meshDataSize = 0
 100            };
 101        }
 102    }
 103}