< 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%110100%
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
 6015    public UUIDEventsPlugin()
 16    {
 6017        inputControllerLegacy = new InputController_Legacy();
 6018        hoverCanvas = LoadAndInstantiate<InteractionHoverCanvasController>("InteractionHoverCanvas");
 19
 6020        pointerEventsController = new PointerEventsController(inputControllerLegacy, hoverCanvas);
 21
 6022        IRuntimeComponentFactory factory = Environment.i.world.componentFactory;
 23
 6024        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_DOWN,
 25            BuildUUIDEventComponent<OnPointerDown>);
 6026        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_UP,
 27            BuildUUIDEventComponent<OnPointerUp>);
 6028        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_CLICK,
 29            BuildUUIDEventComponent<OnClick>);
 6030        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_EXIT,
 31            BuildUUIDEventComponent<OnPointerHoverExit>);
 6032        factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_ENTER,
 33            BuildUUIDEventComponent<OnPointerHoverEnter>);
 34
 6035        factory.createOverrides.Add((int) CLASS_ID_COMPONENT.UUID_CALLBACK, OnUUIDCallbackIsAdded);
 6036    }
 37
 38    private void OnUUIDCallbackIsAdded(string sceneid, long entityid, ref int classId, object data)
 39    {
 6940        OnPointerEvent.Model model = JsonUtility.FromJson<OnPointerEvent.Model>(data as string);
 6941        classId = (int) model.GetClassIdFromType();
 6942    }
 43
 44    public void Dispose()
 45    {
 6046        pointerEventsController.Dispose();
 6047        inputControllerLegacy.Dispose();
 48
 6049        IRuntimeComponentFactory factory = Environment.i.world.componentFactory;
 50
 6051        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_DOWN);
 6052        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_UP);
 6053        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_CLICK);
 6054        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_EXIT);
 6055        factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_ENTER);
 56
 6057        factory.createOverrides.Remove((int) CLASS_ID_COMPONENT.UUID_CALLBACK);
 6058    }
 59
 60    private static T LoadAndInstantiate<T>(string name)
 61    {
 6062        GameObject instance = Object.Instantiate(Resources.Load(name)) as GameObject;
 6063        instance.name = name;
 6064        return instance.GetComponent<T>();
 65    }
 66
 67    private T BuildUUIDEventComponent<T>()
 68        where T : Component
 69    {
 5870        var go = new GameObject("UUID Component");
 5871        T newComponent = go.GetOrCreateComponent<T>();
 5872        return newComponent;
 73    }
 74}