< Summary

Class:BIWOutlinerController
Assembly:BuilderInWorld
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Controllers/BIWOutlinerController.cs
Covered lines:74
Uncovered lines:21
Coverable lines:95
Total lines:206
Line coverage:77.8% (74 of 95)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BIWOutlinerController()0%110100%
Initialize(...)0%110100%
EnterEditMode(...)0%110100%
ExitEditMode()0%110100%
Dispose()0%110100%
SetOutlineCheckActive(...)0%2100%
CheckOutline()0%7.777075%
IsEntityOutlined(...)0%110100%
OutlineEntities(...)0%6200%
OutlineEntity(...)0%8.518080%
CancelUnselectedOutlines()0%12300%
RemoveEntitiesOutlineOutsidePointerOrUnselected()0%440100%
CancelAllOutlines()0%6200%
CancelEntityOutline(...)0%6.046090%
ActivateBuilderInWorldCamera()0%220100%
DeactivateBuilderInWorldCamera()0%3.013090%
RemoveBuilderInWorldCamera()0%3.13077.78%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Controllers/BIWOutlinerController.cs

#LineLine coverage
 1using System;
 2using DCL.Configuration;
 3using DCL.Controllers;
 4using System.Collections.Generic;
 5using DCL.Builder;
 6using UnityEngine;
 7using UnityEngine.Rendering.Universal;
 8
 9public class BIWOutlinerController : BIWController, IBIWOutlinerController
 10{
 11    internal const int OUTLINER_OPTIMIZATION_TIMES = 10;
 12    private const int BUILDER_RENDERER_INDEX = 1;
 13
 14    private Material cameraOutlinerMaterial;
 15
 16    private IBIWRaycastController raycastController;
 17
 618    private readonly List<BIWEntity> entitiesOutlined = new List<BIWEntity>();
 19    private int outlinerOptimizationCounter = 0;
 620    private bool isOutlineCheckActive = true;
 21
 22    public override void Initialize(IContext context)
 23    {
 624        base.Initialize(context);
 625        cameraOutlinerMaterial = context.projectReferencesAsset.cameraOutlinerMaterial;
 26
 627        raycastController = context.editorContext.raycastController;
 628    }
 29
 30    public override void EnterEditMode(IParcelScene scene)
 31    {
 732        base.EnterEditMode(scene);
 733        ActivateBuilderInWorldCamera();
 734    }
 35
 36    public override void ExitEditMode()
 37    {
 138        base.ExitEditMode();
 139        DeactivateBuilderInWorldCamera();
 140    }
 41
 42    public override void Dispose()
 43    {
 644        base.Dispose();
 645        RemoveBuilderInWorldCamera();
 646    }
 47
 048    public void SetOutlineCheckActive(bool isActive) { isOutlineCheckActive = isActive; }
 49
 50    public void CheckOutline()
 51    {
 1152        if (outlinerOptimizationCounter >= OUTLINER_OPTIMIZATION_TIMES && isOutlineCheckActive)
 53        {
 154            if (!BIWUtils.IsPointerOverUIElement() && !BIWUtils.IsPointerOverMaskElement(BIWSettings.GIZMOS_LAYER))
 55            {
 156                BIWEntity entity = raycastController.GetEntityOnPointer();
 157                RemoveEntitiesOutlineOutsidePointerOrUnselected();
 58
 159                if (entity != null && !entity.isSelected)
 060                    OutlineEntity(entity);
 061            }
 62            else
 63            {
 064                CancelUnselectedOutlines();
 65            }
 66
 167            outlinerOptimizationCounter = 0;
 168        }
 69        else
 1070            outlinerOptimizationCounter++;
 1071    }
 72
 473    public bool IsEntityOutlined(BIWEntity entity) { return entitiesOutlined.Contains(entity); }
 74
 75    public void OutlineEntities(List<BIWEntity> entitiesToEdit)
 76    {
 077        foreach (BIWEntity entityToEdit in entitiesToEdit)
 78        {
 079            OutlineEntity(entityToEdit);
 80        }
 081    }
 82
 83    public void OutlineEntity(BIWEntity entity)
 84    {
 485        if (entity.rootEntity.meshRootGameObject == null)
 086            return;
 87
 488        if (!entity.rootEntity.meshRootGameObject && entity.rootEntity.renderers.Length <= 0)
 089            return;
 90
 491        if (entitiesOutlined.Contains(entity))
 092            return;
 93
 494        if (entity.isLocked)
 195            return;
 96
 397        entitiesOutlined.Add(entity);
 98
 1299        for (int i = 0; i < entity.rootEntity.meshesInfo.renderers.Length; i++)
 100        {
 3101            if ( entity.rootEntity.meshesInfo.renderers[i] == null)
 102                continue;
 3103            entity.rootEntity.meshesInfo.renderers[i].gameObject.layer = BIWSettings.SELECTION_LAYER_INDEX;
 104        }
 3105    }
 106
 107    public void CancelUnselectedOutlines()
 108    {
 0109        for (int i = 0; i < entitiesOutlined.Count; i++)
 110        {
 0111            if (!entitiesOutlined[i].isSelected)
 112            {
 0113                CancelEntityOutline(entitiesOutlined[i]);
 114            }
 115        }
 0116    }
 117
 118    public void RemoveEntitiesOutlineOutsidePointerOrUnselected()
 119    {
 1120        var entity = raycastController.GetEntityOnPointer();
 4121        for (int i = 0; i < entitiesOutlined.Count; i++)
 122        {
 1123            if (!entitiesOutlined[i].isSelected || entity != entitiesOutlined[i])
 1124                CancelEntityOutline(entitiesOutlined[i]);
 125        }
 1126    }
 127
 128    public void CancelAllOutlines()
 129    {
 0130        for (int i = 0; i < entitiesOutlined.Count; i++)
 131        {
 0132            CancelEntityOutline(entitiesOutlined[i]);
 133        }
 0134    }
 135
 136    public void CancelEntityOutline(BIWEntity entityToQuitOutline)
 137    {
 3138        if (!entitiesOutlined.Contains(entityToQuitOutline))
 0139            return;
 140
 3141        if (entityToQuitOutline.rootEntity.meshRootGameObject && entityToQuitOutline.rootEntity.meshesInfo.renderers.Len
 142        {
 12143            for (int x = 0; x < entityToQuitOutline.rootEntity.meshesInfo.renderers.Length; x++)
 144            {
 3145                if ( entityToQuitOutline.rootEntity.meshesInfo.renderers[x] == null)
 146                    continue;
 3147                entityToQuitOutline.rootEntity.meshesInfo.renderers[x].gameObject.layer = BIWSettings.DEFAULT_LAYER_INDE
 148            }
 149        }
 150
 3151        entitiesOutlined.Remove(entityToQuitOutline);
 3152    }
 153
 154    private void ActivateBuilderInWorldCamera()
 155    {
 7156        Camera camera = Camera.main;
 7157        BIWOutline outliner = camera.GetComponent<BIWOutline>();
 7158        if (outliner == null)
 159        {
 6160            outliner = camera.gameObject.AddComponent(typeof(BIWOutline)) as BIWOutline;
 6161            outliner.SetOutlineMaterial(cameraOutlinerMaterial);
 6162        }
 163        else
 164        {
 1165            outliner.enabled = true;
 166        }
 167
 7168        outliner.Activate();
 169
 7170        UniversalAdditionalCameraData additionalCameraData = camera.transform.GetComponent<UniversalAdditionalCameraData
 7171        additionalCameraData.SetRenderer(BUILDER_RENDERER_INDEX);
 7172    }
 173
 174    private void DeactivateBuilderInWorldCamera()
 175    {
 1176        Camera camera = Camera.main;
 177
 1178        if (camera == null)
 0179            return;
 180
 1181        BIWOutline outliner = camera.GetComponent<BIWOutline>();
 1182        if (outliner != null)
 183        {
 1184            outliner.enabled = false;
 1185            outliner.Deactivate();
 186        }
 187
 1188        UniversalAdditionalCameraData additionalCameraData = camera.transform.GetComponent<UniversalAdditionalCameraData
 1189        additionalCameraData.SetRenderer(0);
 1190    }
 191
 192    private void RemoveBuilderInWorldCamera()
 193    {
 6194        Camera camera = Camera.main;
 195
 6196        if (camera == null)
 0197            return;
 198
 6199        BIWOutline outliner = camera.GetComponent<BIWOutline>();
 6200        if (outliner == null)
 0201            return;
 202
 6203        outliner.Dispose();
 6204        GameObject.Destroy(outliner);
 6205    }
 206}