< Summary

Class:DCL.ECSComponents.AvatarShapeRegister
Assembly:DCL.ECSComponents.AvatarShape
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/AvatarShape/AvatarShapeRegister.cs
Covered lines:20
Uncovered lines:0
Coverable lines:20
Total lines:53
Line coverage:100% (20 of 20)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AvatarShapeRegister(...)0%110100%
Dispose()0%110100%
ConfigurePool(...)0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/AvatarShape/AvatarShapeRegister.cs

#LineLine coverage
 1using System;
 2using DCL.ECSRuntime;
 3using UnityEngine;
 4
 5namespace DCL.ECSComponents
 6{
 7    public class AvatarShapeRegister : IDisposable
 8    {
 9        private const string AVATAR_POOL_NAME = "AvatarShapeECS7";
 10        private const string AVATAR_PREFAB_PATH = "NewAvatarShape";
 11
 12        private readonly ECSComponentsFactory factory;
 13        private readonly IECSComponentWriter componentWriter;
 14        private readonly int componentId;
 15
 16        private Pool pool;
 17
 2118        public AvatarShapeRegister(int componentId, ECSComponentsFactory factory, IECSComponentWriter componentWriter)
 19        {
 2120            AvatarShape avatarShapePrefab = Resources.Load<AvatarShape>(AVATAR_PREFAB_PATH);
 2121            ConfigurePool(avatarShapePrefab.gameObject);
 2122            factory.AddOrReplaceComponent(componentId, AvatarShapeSerializer.Deserialize, () => new AvatarShapeComponent
 2123            componentWriter.AddOrReplaceComponentSerializer<PBAvatarShape>(componentId, AvatarShapeSerializer.Serialize)
 24
 2125            this.factory = factory;
 2126            this.componentWriter = componentWriter;
 2127            this.componentId = componentId;
 2128        }
 29
 30        public void Dispose()
 31        {
 232            factory.RemoveComponent(componentId);
 233            componentWriter.RemoveComponentSerializer(componentId);
 34
 235            PoolManager.i.RemovePool(AVATAR_POOL_NAME);
 236            pool.ReleaseAll();
 237        }
 38
 39        internal void ConfigurePool(GameObject prefab)
 40        {
 2141            pool = PoolManager.i.GetPool(AVATAR_POOL_NAME);
 2142            if (pool != null)
 1843                return;
 44
 345            pool = PoolManager.i.AddPool(
 46                AVATAR_POOL_NAME,
 47                GameObject.Instantiate(prefab).gameObject,
 48                isPersistent: true);
 49
 350            pool.ForcePrewarm();
 351        }
 52    }
 53}