< Summary

Class:CoreComponentsPlugin
Assembly:DCL.Plugins.CoreComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/CoreComponentsPlugin/CoreComponentsPlugin.cs
Covered lines:89
Uncovered lines:2
Coverable lines:91
Total lines:160
Line coverage:97.8% (89 of 91)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CoreComponentsPlugin()0%110100%
PrewarmPoolablePools()0%330100%
HandleAvatarAttachExclusivity(...)0%2.152066.67%
BuildComponent[T]()0%110100%
BuildPoolableComponent(...)0%110100%
Dispose()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/CoreComponentsPlugin/CoreComponentsPlugin.cs

#LineLine coverage
 1using System.Collections;
 2using DCL;
 3using DCL.Components;
 4using DCL.Controllers;
 5using DCL.Models;
 6using UnityEngine;
 7
 8public class CoreComponentsPlugin : IPlugin
 9{
 10    private PoolableComponentFactory poolableComponentFactory;
 11
 32012    public CoreComponentsPlugin()
 13    {
 32014        poolableComponentFactory = Resources.Load<PoolableComponentFactory>("PoolableCoreComponentsFactory");
 32015        IRuntimeComponentFactory factory = Environment.i.world.componentFactory;
 16
 17        // Transform
 32018        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.TRANSFORM, BuildComponent<DCLTransform>);
 32019        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.AVATAR_ATTACH, BuildComponent<AvatarAttachComponent>);
 20
 21        // Shapes
 32022        factory.RegisterBuilder((int) CLASS_ID.BOX_SHAPE, BuildComponent<BoxShape>);
 32023        factory.RegisterBuilder((int) CLASS_ID.SPHERE_SHAPE, BuildComponent<SphereShape>);
 32024        factory.RegisterBuilder((int) CLASS_ID.CYLINDER_SHAPE, BuildComponent<CylinderShape>);
 32025        factory.RegisterBuilder((int) CLASS_ID.CONE_SHAPE, BuildComponent<ConeShape>);
 32026        factory.RegisterBuilder((int) CLASS_ID.PLANE_SHAPE, BuildComponent<PlaneShape>);
 32027        factory.RegisterBuilder((int) CLASS_ID.GLTF_SHAPE, BuildComponent<GLTFShape>);
 32028        factory.RegisterBuilder((int) CLASS_ID.OBJ_SHAPE, BuildComponent<OBJShape>);
 32029        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.TEXT_SHAPE,
 1130            () => BuildPoolableComponent((int) CLASS_ID_COMPONENT.TEXT_SHAPE));
 31        //
 32032        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.BILLBOARD,
 433            () => BuildPoolableComponent((int) CLASS_ID_COMPONENT.BILLBOARD));
 32034        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.SMART_ITEM,
 135            () => BuildPoolableComponent((int) CLASS_ID_COMPONENT.SMART_ITEM));
 36
 37        // Materials
 32038        factory.RegisterBuilder((int) CLASS_ID.BASIC_MATERIAL, BuildComponent<BasicMaterial>);
 32039        factory.RegisterBuilder((int) CLASS_ID.PBR_MATERIAL, BuildComponent<PBRMaterial>);
 32040        factory.RegisterBuilder((int) CLASS_ID.TEXTURE, BuildComponent<DCLTexture>);
 32041        factory.RegisterBuilder((int) CLASS_ID.AVATAR_TEXTURE, BuildComponent<DCLAvatarTexture>);
 42
 43        // Audio
 32044        factory.RegisterBuilder((int) CLASS_ID.AUDIO_CLIP, BuildComponent<DCLAudioClip>);
 32045        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.AUDIO_SOURCE,
 1546            () => BuildPoolableComponent((int) CLASS_ID_COMPONENT.AUDIO_SOURCE));
 32047        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.AUDIO_STREAM,
 448            () => BuildPoolableComponent((int) CLASS_ID_COMPONENT.AUDIO_STREAM));
 49
 50        // Video
 32051        factory.RegisterBuilder((int) CLASS_ID.VIDEO_CLIP, BuildComponent<DCLVideoClip>);
 32052        factory.RegisterBuilder((int) CLASS_ID.VIDEO_TEXTURE, BuildComponent<DCLVideoTexture>);
 53
 54        // Others
 32055        factory.RegisterBuilder((int) CLASS_ID.FONT, BuildComponent<DCLFont>);
 32056        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.AVATAR_SHAPE,
 557            () => BuildPoolableComponent((int) CLASS_ID_COMPONENT.AVATAR_SHAPE));
 32058        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.ANIMATOR,
 859            () => BuildPoolableComponent((int) CLASS_ID_COMPONENT.ANIMATOR));
 32060        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.GIZMOS,
 161            () => BuildPoolableComponent((int) CLASS_ID_COMPONENT.GIZMOS));
 32062        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.AVATAR_MODIFIER_AREA,
 863            () => BuildPoolableComponent((int) CLASS_ID_COMPONENT.AVATAR_MODIFIER_AREA));
 32064        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.QUEST_TRACKING_INFORMATION,
 565            () => BuildPoolableComponent((int) CLASS_ID_COMPONENT.QUEST_TRACKING_INFORMATION));
 32066        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.CAMERA_MODE_AREA, BuildComponent<CameraModeArea>);
 67
 32068        factory.createOverrides.Add((int) CLASS_ID_COMPONENT.TRANSFORM, HandleAvatarAttachExclusivity);
 69
 32070        CoroutineStarter.Start(PrewarmPoolablePools());
 32071    }
 72
 73    IEnumerator PrewarmPoolablePools()
 74    {
 32075        yield return null;
 32076        poolableComponentFactory.PrewarmPools();
 32077    }
 78
 79    private void HandleAvatarAttachExclusivity(int sceneNumber, long entityid, ref int classid, object data)
 80    {
 81        // NOTE: TRANSFORM and AVATAR_ATTACH can't be used in the same Entity at the same time.
 82        // so we remove AVATAR_ATTACH (if exists) when a TRANSFORM is created.
 24283        IParcelScene scene = Environment.i.world.state.GetScene(sceneNumber);
 24284        IDCLEntity entity = scene.entities[entityid];
 85
 24286        if (scene.componentsManagerLegacy.TryGetBaseComponent(entity, CLASS_ID_COMPONENT.AVATAR_ATTACH, out IEntityCompo
 87        {
 088            component.Cleanup();
 089            scene.componentsManagerLegacy.RemoveComponent(entity, CLASS_ID_COMPONENT.AVATAR_ATTACH);
 90        }
 24291    }
 92
 93    protected T BuildComponent<T>()
 94        where T : IComponent, new()
 95    {
 60596        return new T();
 97    }
 98
 99    private IComponent BuildPoolableComponent(int classId)
 100    {
 62101        return poolableComponentFactory.CreateItemFromId<BaseComponent>((CLASS_ID_COMPONENT) classId);
 102    }
 103
 104    public void Dispose()
 105    {
 320106        IRuntimeComponentFactory factory = Environment.i.world.componentFactory;
 107
 320108        if (factory == null)
 3109            return;
 110
 111        // Transform
 317112        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.TRANSFORM);
 317113        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.AVATAR_ATTACH);
 114
 115        // Shapes
 317116        factory.UnregisterBuilder((int) CLASS_ID.BOX_SHAPE);
 317117        factory.UnregisterBuilder((int) CLASS_ID.SPHERE_SHAPE);
 317118        factory.UnregisterBuilder((int) CLASS_ID.CYLINDER_SHAPE);
 317119        factory.UnregisterBuilder((int) CLASS_ID.CONE_SHAPE);
 317120        factory.UnregisterBuilder((int) CLASS_ID.PLANE_SHAPE);
 317121        factory.UnregisterBuilder((int) CLASS_ID.GLTF_SHAPE);
 317122        factory.UnregisterBuilder((int) CLASS_ID.OBJ_SHAPE);
 317123        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.TEXT_SHAPE);
 124        //
 317125        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.BILLBOARD);
 317126        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.SMART_ITEM);
 127
 128        // Materials
 317129        factory.UnregisterBuilder((int) CLASS_ID.BASIC_MATERIAL);
 317130        factory.UnregisterBuilder((int) CLASS_ID.PBR_MATERIAL);
 317131        factory.UnregisterBuilder((int) CLASS_ID.TEXTURE);
 317132        factory.UnregisterBuilder((int) CLASS_ID.AVATAR_TEXTURE);
 133
 134        // Audio
 317135        factory.UnregisterBuilder((int) CLASS_ID.AUDIO_CLIP);
 317136        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.AUDIO_SOURCE);
 317137        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.AUDIO_STREAM);
 138
 139        // Video
 317140        factory.UnregisterBuilder((int) CLASS_ID.VIDEO_CLIP);
 317141        factory.UnregisterBuilder((int) CLASS_ID.VIDEO_TEXTURE);
 142
 143        // Builder in world
 317144        factory.UnregisterBuilder((int) CLASS_ID.NAME);
 317145        factory.UnregisterBuilder((int) CLASS_ID.LOCKED_ON_EDIT);
 317146        factory.UnregisterBuilder((int) CLASS_ID.VISIBLE_ON_EDIT);
 147
 148        // Others
 317149        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.AVATAR_SHAPE);
 317150        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.ANIMATOR);
 317151        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.GIZMOS);
 317152        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.AVATAR_MODIFIER_AREA);
 317153        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.QUEST_TRACKING_INFORMATION);
 317154        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.CAMERA_MODE_AREA);
 317155        factory.UnregisterBuilder((int) CLASS_ID.FONT);
 156
 157
 317158        factory.createOverrides.Remove((int) CLASS_ID_COMPONENT.TRANSFORM);
 317159    }
 160}