< Summary

Class:PreviewMenuController
Assembly:DebugPlugins_PreviewMenu
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/DebugPlugins/PreviewMenu/PreviewMenuController.cs
Covered lines:31
Uncovered lines:0
Coverable lines:31
Total lines:76
Line coverage:100% (31 of 31)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PreviewMenuController()0%110100%
Dispose()0%110100%
IsFPSPanelOn()0%110100%
OnFPSPanelToggle(...)0%110100%
IsBoundingBoxOn()0%220100%
OnBoundingBoxToggle(...)0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/DebugPlugins/PreviewMenu/PreviewMenuController.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using DCL;
 4using UnityEngine;
 5using Object = UnityEngine.Object;
 6
 7internal class PreviewMenuController : IDisposable
 8{
 9    internal const string MENU_VIEW_RES_PATH = "PreviewMenuView";
 10    internal const string TOGGLEVISIBILITY_VIEW_RES_PATH = "PreviewMenuVisibilityToggle";
 11    internal const string POSITION_VIEW_RES_PATH = "PreviewMenuPositionView";
 12
 13    internal readonly PreviewMenuView menuView;
 14
 15    internal readonly PreviewMenuVisibilityToggleView showFps;
 16    internal readonly PreviewMenuVisibilityToggleView showBoundingBox;
 17    internal readonly PreviewMenuPositionView positionView;
 18
 519    public PreviewMenuController()
 20    {
 521        var menuViewResource = Resources.Load<PreviewMenuView>(MENU_VIEW_RES_PATH);
 522        menuView = Object.Instantiate(menuViewResource);
 523        menuView.name = "_PreviewMenu";
 524        menuView.SetVisible(false);
 25
 526        var visibilityToggleViewResource = Resources.Load<PreviewMenuVisibilityToggleView>(TOGGLEVISIBILITY_VIEW_RES_PAT
 527        showFps = Object.Instantiate(visibilityToggleViewResource);
 528        showFps.SetUp("FPS PANEL", IsFPSPanelOn, OnFPSPanelToggle);
 29
 530        showBoundingBox = Object.Instantiate(visibilityToggleViewResource);
 531        showBoundingBox.SetUp("BOUNDING BOXES", IsBoundingBoxOn, OnBoundingBoxToggle);
 32
 533        var positionViewResource = Resources.Load<PreviewMenuPositionView>(POSITION_VIEW_RES_PATH);
 534        positionView = Object.Instantiate(positionViewResource);
 35
 536        menuView.AddMenuItem(positionView.transform);
 537        menuView.AddMenuItem(showFps.transform);
 538        menuView.AddMenuItem(showBoundingBox.transform);
 539    }
 40
 41    public void Dispose()
 42    {
 543        positionView.Dispose();
 544        showBoundingBox.Dispose();
 545        showFps.Dispose();
 546        menuView.Dispose();
 547    }
 48
 49    private static bool IsFPSPanelOn()
 50    {
 651        return DataStore.i.debugConfig.isFPSPanelVisible.Get();
 52    }
 53
 54    private static void OnFPSPanelToggle(bool isOn)
 55    {
 156        DataStore.i.debugConfig.isFPSPanelVisible.Set(isOn);
 157    }
 58
 59    private static bool IsBoundingBoxOn()
 60    {
 661        return DataStore.i.debugConfig.showSceneBoundingBoxes.Get()
 162                        .Any(pair => pair.Value);
 63    }
 64
 65    private static void OnBoundingBoxToggle(bool isOn)
 66    {
 167        var sceneIds = DataStore.i.debugConfig.showSceneBoundingBoxes.Get()
 168                                .Select(pair => pair.Key)
 69                                .ToArray();
 70
 471        foreach (var sceneId in sceneIds)
 72        {
 173            DataStore.i.debugConfig.showSceneBoundingBoxes.AddOrSet(sceneId, isOn);
 74        }
 175    }
 76}