< Summary

Class:UUIDEventsPlugin
Assembly:DCL.Plugins.UUIDEventComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/UUIDEventComponentsPlugin/UUIDEventsPlugin.cs
Covered lines:33
Uncovered lines:2
Coverable lines:35
Total lines:80
Line coverage:94.2% (33 of 35)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:5
Method coverage:100% (5 of 5)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UUIDEventsPlugin()0%330100%
OnUUIDCallbackIsAdded(...)0%3.213071.43%
Dispose()0%110100%
LoadAndInstantiate[T](...)0%110100%
BuildUUIDEventComponent[T]()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/UUIDEventComponentsPlugin/UUIDEventsPlugin.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using DCL;
 4using DCL.Components;
 5using DCL.Helpers;
 6using DCL.Models;
 7using UnityEngine;
 8using Decentraland.Sdk.Ecs6;
 9
 10public class UUIDEventsPlugin : IPlugin
 11{
 12    public PointerEventsController pointerEventsController;
 13    public InputController_Legacy inputControllerLegacy;
 14    public InteractionHoverCanvasController hoverCanvas;
 15
 8516    public UUIDEventsPlugin()
 17    {
 8518        inputControllerLegacy = new InputController_Legacy();
 8519        hoverCanvas = LoadAndInstantiate<InteractionHoverCanvasController>("InteractionHoverCanvas");
 20
 8521        pointerEventsController = new PointerEventsController(inputControllerLegacy, hoverCanvas, SceneReferences.i?.mou
 22
 8523        IRuntimeComponentFactory factory = Environment.i.world.componentFactory;
 24
 8525        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_DOWN,
 26            BuildUUIDEventComponent<OnPointerDown>);
 8527        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_UP,
 28            BuildUUIDEventComponent<OnPointerUp>);
 8529        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_CLICK,
 30            BuildUUIDEventComponent<OnClick>);
 8531        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_EXIT,
 32            BuildUUIDEventComponent<OnPointerHoverExit>);
 8533        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_ENTER,
 34            BuildUUIDEventComponent<OnPointerHoverEnter>);
 35
 8536        factory.createOverrides.Add((int) CLASS_ID_COMPONENT.UUID_CALLBACK, OnUUIDCallbackIsAdded);
 8537    }
 38
 39    private void OnUUIDCallbackIsAdded(int sceneNumber, long entityid, ref int classId, object data)
 40    {
 7041        OnPointerEvent.Model model = new OnPointerEvent.Model();
 7042        if (data is string json)
 7043            model = (OnPointerEvent.Model)model.GetDataFromJSON(json);
 044        else if (data is Decentraland.Sdk.Ecs6.ComponentBodyPayload payload)
 045            model = (OnPointerEvent.Model)model.GetDataFromPb(payload);
 46
 7047        classId = (int) model.GetClassIdFromType();
 7048    }
 49
 50    public void Dispose()
 51    {
 8552        pointerEventsController.Dispose();
 8553        inputControllerLegacy.Dispose();
 54
 8555        IRuntimeComponentFactory factory = Environment.i.world.componentFactory;
 56
 8557        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_DOWN);
 8558        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_UP);
 8559        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_CLICK);
 8560        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_EXIT);
 8561        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_ENTER);
 62
 8563        factory.createOverrides.Remove((int) CLASS_ID_COMPONENT.UUID_CALLBACK);
 8564    }
 65
 66    private static T LoadAndInstantiate<T>(string name)
 67    {
 8568        GameObject instance = Object.Instantiate(Resources.Load(name)) as GameObject;
 8569        instance.name = name;
 8570        return instance.GetComponent<T>();
 71    }
 72
 73    private T BuildUUIDEventComponent<T>()
 74        where T : Component
 75    {
 5976        var go = new GameObject("UUID Component");
 5977        T newComponent = go.GetOrCreateComponent<T>();
 5978        return newComponent;
 79    }
 80}