< Summary

Class:DCL.ECS7.InternalComponents.InternalSceneBoundsCheckExtensions
Assembly:ECS7Plugin.InternalECSComponents.Interfaces
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/InternalECSComponents/Interfaces/Extensions/InternalSceneBoundsCheckExtensions.cs
Covered lines:24
Uncovered lines:25
Coverable lines:49
Total lines:128
Line coverage:48.9% (24 of 49)
Covered branches:0
Total branches:0
Covered methods:4
Total methods:8
Method coverage:50% (4 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetPosition(...)0%7.397080%
OnTransformScaleRotationChanged(...)0%4.434070%
SetRenderers(...)0%6200%
SetPhysicsColliders(...)0%6200%
SetPointerColliders(...)0%6200%
RegisterOnSceneBoundsStateChangeCallback(...)0%220100%
RemoveOnSceneBoundsStateChangeCallback(...)0%6.984042.86%
IsFullyDefaulted(...)0%42600%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/InternalECSComponents/Interfaces/Extensions/InternalSceneBoundsCheckExtensions.cs

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.Models;
 3using System;
 4using System.Collections.Generic;
 5using UnityEngine;
 6
 7namespace DCL.ECS7.InternalComponents
 8{
 9    public static class InternalSceneBoundsCheckExtensions
 10    {
 11        public static void SetPosition(this IInternalECSComponent<InternalSceneBoundsCheck> sbcInternalComponent,
 12            IParcelScene scene, IDCLEntity entity, Vector3 newEntityPosition, bool createComponentIfMissing = true)
 13        {
 2814            var model = sbcInternalComponent.GetFor(scene, entity.entityId)?.model;
 15
 16            InternalSceneBoundsCheck finalModel;
 2817            if (model == null)
 18            {
 2519                if (!createComponentIfMissing)
 320                    return;
 21
 2222                finalModel = new InternalSceneBoundsCheck(new Bounds());
 23            }
 24            else
 25            {
 326                finalModel = model.Value;
 27            }
 28
 2529            finalModel.entityPosition = newEntityPosition;
 30
 2531            sbcInternalComponent.PutFor(scene, entity.entityId, finalModel);
 32
 33            // Update children position in their SBCComponent as well
 2534            IList<long> childrenId = entity.childrenId;
 5035            for (int i = 0; i < childrenId.Count; i++)
 36            {
 037                if (scene.entities.TryGetValue(childrenId[i], out IDCLEntity childEntity))
 38                {
 039                    sbcInternalComponent.SetPosition(scene, childEntity, childEntity.gameObject.transform.position, crea
 40                }
 41            }
 2542        }
 43
 44        public static void OnTransformScaleRotationChanged(this IInternalECSComponent<InternalSceneBoundsCheck> sbcInter
 45            IParcelScene scene, IDCLEntity entity)
 46        {
 1047            var model = sbcInternalComponent.GetFor(scene, entity)?.model ?? new InternalSceneBoundsCheck(new Bounds());
 48
 49            // Mesh bounds need to be recalculated
 1050            model.meshesDirty = true;
 51
 1052            sbcInternalComponent.PutFor(scene, entity, model);
 53
 54            // Update children 'meshesDirty' in their SBCComponent as well
 1055            IList<long> childrenId = entity.childrenId;
 2056            for (int i = 0; i < childrenId.Count; i++)
 57            {
 058                if (scene.entities.TryGetValue(childrenId[i], out IDCLEntity childEntity))
 59                {
 060                    sbcInternalComponent.OnTransformScaleRotationChanged(scene, childEntity);
 61                }
 62            }
 1063        }
 64
 65        public static void SetRenderers(this IInternalECSComponent<InternalSceneBoundsCheck> sbcInternalComponent,
 66            IParcelScene scene, IDCLEntity entity, IList<Renderer> newRenderersCollection)
 67        {
 068            var model = sbcInternalComponent.GetFor(scene, entity)?.model ?? new InternalSceneBoundsCheck(new Bounds());
 069            model.renderers = newRenderersCollection;
 070            model.meshesDirty = true;
 71
 072            sbcInternalComponent.PutFor(scene, entity, model);
 073        }
 74
 75        public static void SetPhysicsColliders(this IInternalECSComponent<InternalSceneBoundsCheck> sbcInternalComponent
 76            IParcelScene scene, IDCLEntity entity, KeyValueSet<Collider, uint> newCollidersCollection)
 77        {
 078            var model = sbcInternalComponent.GetFor(scene, entity)?.model ?? new InternalSceneBoundsCheck(new Bounds());
 079            model.physicsColliders = newCollidersCollection;
 080            model.meshesDirty = true;
 81
 082            sbcInternalComponent.PutFor(scene, entity, model);
 083        }
 84
 85        public static void SetPointerColliders(this IInternalECSComponent<InternalSceneBoundsCheck> sbcInternalComponent
 86            IParcelScene scene, IDCLEntity entity, KeyValueSet<Collider, uint> newCollidersCollection)
 87        {
 088            var model = sbcInternalComponent.GetFor(scene, entity)?.model ?? new InternalSceneBoundsCheck(new Bounds());
 089            model.pointerColliders = newCollidersCollection;
 090            model.meshesDirty = true;
 91
 092            sbcInternalComponent.PutFor(scene, entity, model);
 093        }
 94
 95        public static void RegisterOnSceneBoundsStateChangeCallback(this IInternalECSComponent<InternalSceneBoundsCheck>
 96            IParcelScene scene, IDCLEntity entity, Action<bool> callback)
 97        {
 1198            var model = sbcInternalComponent.GetFor(scene, entity)?.model ?? new InternalSceneBoundsCheck(new Bounds());
 1199            model.OnSceneBoundsStateChange += callback;
 100
 11101            sbcInternalComponent.PutFor(scene, entity, model);
 11102        }
 103
 104        public static void RemoveOnSceneBoundsStateChangeCallback(this IInternalECSComponent<InternalSceneBoundsCheck> s
 105            IParcelScene scene, IDCLEntity entity, Action<bool> callback)
 106        {
 12107            var model = sbcInternalComponent.GetFor(scene, entity)?.model;
 108
 12109            if (model == null)
 12110                return;
 111
 0112            InternalSceneBoundsCheck finalModel = model.Value;
 0113            finalModel.OnSceneBoundsStateChange -= callback;
 114
 0115            sbcInternalComponent.PutFor(scene, entity, finalModel);
 0116        }
 117
 118        public static bool IsFullyDefaulted(this IInternalECSComponent<InternalSceneBoundsCheck> sbcInternalComponent,
 119            IParcelScene scene, IDCLEntity entity)
 120        {
 0121            var model = sbcInternalComponent.GetFor(scene, entity)?.model;
 122
 0123            return model == null || (model.Value.entityPosition == Vector3.zero
 124                                     && model.Value.entityLocalMeshBounds.size == Vector3.zero
 125                                     && model.Value.OnSceneBoundsStateChange == null);
 126        }
 127    }
 128}