< Summary

Class:DCL.Controllers.DCLVideoTextureUtils
Assembly:DCL.Components.Video
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Video/DCLVideoTextureUtils.cs
Covered lines:36
Uncovered lines:8
Coverable lines:44
Total lines:96
Line coverage:81.8% (36 of 44)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetClosestDistanceSqr(...)0%5.015091.67%
IsComponentVisible(...)0%440100%
IsEntityVisible(...)0%3.073080%
UnsubscribeToEntityShapeUpdate(...)0%6.83025%
SubscribeToEntityUpdates(...)0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Video/DCLVideoTextureUtils.cs

#LineLine coverage
 1using DCL.Components;
 2using DCL.Models;
 3using UnityEngine;
 4
 5namespace DCL.Controllers
 6{
 7    public static class DCLVideoTextureUtils
 8    {
 9        public static float GetClosestDistanceSqr(ISharedComponent disposableComponent, Vector3 fromPosition)
 10        {
 911            float dist = int.MaxValue;
 12
 913            if (disposableComponent.GetAttachedEntities().Count <= 0)
 014                return dist;
 15
 916            using (var iterator = disposableComponent.GetAttachedEntities().GetEnumerator())
 17            {
 1818                while (iterator.MoveNext())
 19                {
 920                    IDCLEntity entity = iterator.Current;
 21
 922                    if (IsEntityVisible(iterator.Current))
 23                    {
 924                        var entityDist = (entity.meshRootGameObject.transform.position - fromPosition).sqrMagnitude;
 925                        if (entityDist < dist)
 926                            dist = entityDist;
 27                    }
 28                }
 929            }
 30
 931            return dist;
 32        }
 33
 34        public static bool IsComponentVisible(ISharedComponent disposableComponent)
 35        {
 2736            if (disposableComponent.GetAttachedEntities().Count <= 0)
 937                return false;
 38
 1839            using (var iterator = disposableComponent.GetAttachedEntities().GetEnumerator())
 40            {
 2741                while (iterator.MoveNext())
 42                {
 1843                    bool isEntityVisible = IsEntityVisible(iterator.Current);
 44
 1845                    if (isEntityVisible)
 946                        return true;
 47                }
 948            }
 49
 950            return false;
 951        }
 52
 53        public static bool IsEntityVisible(IDCLEntity entity)
 54        {
 2755            if (entity.meshesInfo == null)
 056                return false;
 57
 2758            if (entity.meshesInfo.currentShape == null)
 759                return false;
 60
 2061            return entity.meshesInfo.currentShape.IsVisible();
 62        }
 63
 64        public static void UnsubscribeToEntityShapeUpdate(ISharedComponent component,
 65            System.Action<IDCLEntity> OnUpdate)
 66        {
 167            if (component.GetAttachedEntities().Count <= 0)
 168                return;
 69
 070            using (var iterator = component.GetAttachedEntities().GetEnumerator())
 71            {
 072                while (iterator.MoveNext())
 73                {
 074                    var entity = iterator.Current;
 075                    entity.OnShapeUpdated -= OnUpdate;
 76                }
 077            }
 078        }
 79
 80        public static void SubscribeToEntityUpdates(ISharedComponent component, System.Action<IDCLEntity> OnUpdate)
 81        {
 1082            if (component.GetAttachedEntities().Count <= 0)
 283                return;
 84
 885            using (var iterator = component.GetAttachedEntities().GetEnumerator())
 86            {
 1687                while (iterator.MoveNext())
 88                {
 889                    var entity = iterator.Current;
 890                    entity.OnShapeUpdated -= OnUpdate;
 891                    entity.OnShapeUpdated += OnUpdate;
 92                }
 893            }
 894        }
 95    }
 96}