< Summary

Class:UUIDEventsPlugin
Assembly:DCL.Plugins.UUIDEventComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/UUIDEventComponentsPlugin/UUIDEventsPlugin.cs
Covered lines:31
Uncovered lines:0
Coverable lines:31
Total lines:74
Line coverage:100% (31 of 31)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UUIDEventsPlugin()0%330100%
OnUUIDCallbackIsAdded(...)0%110100%
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;
 8
 9public class UUIDEventsPlugin : IPlugin
 10{
 11    public PointerEventsController pointerEventsController;
 12    public InputController_Legacy inputControllerLegacy;
 13    public InteractionHoverCanvasController hoverCanvas;
 14
 8515    public UUIDEventsPlugin()
 16    {
 8517        inputControllerLegacy = new InputController_Legacy();
 8518        hoverCanvas = LoadAndInstantiate<InteractionHoverCanvasController>("InteractionHoverCanvas");
 19
 8520        pointerEventsController = new PointerEventsController(inputControllerLegacy, hoverCanvas, SceneReferences.i?.mou
 21
 8522        IRuntimeComponentFactory factory = Environment.i.world.componentFactory;
 23
 8524        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_DOWN,
 25            BuildUUIDEventComponent<OnPointerDown>);
 8526        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_UP,
 27            BuildUUIDEventComponent<OnPointerUp>);
 8528        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_CLICK,
 29            BuildUUIDEventComponent<OnClick>);
 8530        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_EXIT,
 31            BuildUUIDEventComponent<OnPointerHoverExit>);
 8532        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_ENTER,
 33            BuildUUIDEventComponent<OnPointerHoverEnter>);
 34
 8535        factory.createOverrides.Add((int) CLASS_ID_COMPONENT.UUID_CALLBACK, OnUUIDCallbackIsAdded);
 8536    }
 37
 38    private void OnUUIDCallbackIsAdded(int sceneNumber, long entityid, ref int classId, object data)
 39    {
 7040        OnPointerEvent.Model model = JsonUtility.FromJson<OnPointerEvent.Model>(data as string);
 7041        classId = (int) model.GetClassIdFromType();
 7042    }
 43
 44    public void Dispose()
 45    {
 8546        pointerEventsController.Dispose();
 8547        inputControllerLegacy.Dispose();
 48
 8549        IRuntimeComponentFactory factory = Environment.i.world.componentFactory;
 50
 8551        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_DOWN);
 8552        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_UP);
 8553        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_CLICK);
 8554        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_EXIT);
 8555        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_ENTER);
 56
 8557        factory.createOverrides.Remove((int) CLASS_ID_COMPONENT.UUID_CALLBACK);
 8558    }
 59
 60    private static T LoadAndInstantiate<T>(string name)
 61    {
 8562        GameObject instance = Object.Instantiate(Resources.Load(name)) as GameObject;
 8563        instance.name = name;
 8564        return instance.GetComponent<T>();
 65    }
 66
 67    private T BuildUUIDEventComponent<T>()
 68        where T : Component
 69    {
 5970        var go = new GameObject("UUID Component");
 5971        T newComponent = go.GetOrCreateComponent<T>();
 5972        return newComponent;
 73    }
 74}