< Summary

Class:DCL.Models.DecentralandEntity
Assembly:DCL.Runtime
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/DecentralandEntity.cs
Covered lines:66
Uncovered lines:6
Coverable lines:72
Total lines:144
Line coverage:91.6% (66 of 72)
Covered branches:0
Total branches:0
Covered methods:50
Total methods:54
Method coverage:92.5% (50 of 54)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DecentralandEntity()0%110100%
AddChild(...)0%220100%
RemoveChild(...)0%220100%
SetParent(...)0%660100%
EnsureMeshGameObject(...)0%330100%
ResetRelease()0%2100%
Cleanup()0%8.018094.44%
UpdateInsideBoundariesStatus(...)0%220100%
UpdateOuterBoundariesStatus(...)0%2.152066.67%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/DecentralandEntity.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Controllers;
 4using DCL.Helpers;
 5using UnityEngine;
 6
 7namespace DCL.Models
 8{
 9    [Serializable]
 10    public class DecentralandEntity : IDCLEntity
 11    {
 367312        public IParcelScene scene { get; set; }
 23913        public bool markedForCleanup { get; set; } = false;
 14
 15        // We let the SceneBoundsChecker update these values later
 100916        public bool isInsideSceneOuterBoundaries { get; private set; } = true;
 182017        public bool isInsideSceneBoundaries { get; private set; } = true;
 18
 84719        public Dictionary<long, IDCLEntity> children { get; private set; } = new Dictionary<long, IDCLEntity>();
 26720        public IDCLEntity parent { get; private set; }
 1175221        public GameObject gameObject { get; set; }
 631322        public long entityId { get; set; }
 3767023        public MeshesInfo meshesInfo { get; set; }
 389024        public GameObject meshRootGameObject => meshesInfo.meshRootGameObject;
 025        public Renderer[] renderers => meshesInfo.renderers;
 26
 27
 256828        public Action<IDCLEntity> OnShapeUpdated { get; set; }
 14129        public Action<IDCLEntity> OnShapeLoaded { get; set; }
 030        public Action<object> OnNameChange { get; set; }
 47031        public Action<Vector3, Quaternion> OnTransformChange { get; set; }
 164232        public Action<IDCLEntity> OnRemoved { get; set; }
 68933        public Action<IDCLEntity> OnMeshesInfoUpdated { get; set; }
 17134        public Action<IDCLEntity> OnMeshesInfoCleaned { get; set; }
 24435        public Action<CLASS_ID_COMPONENT, IDCLEntity> OnBaseComponentAdded { get; set; }
 32636        public Action<IDCLEntity, bool> OnInsideBoundariesChanged { get; set; }
 26237        public Action<IDCLEntity, bool> OnOuterBoundariesChanged { get; set; }
 38
 327239        public Action<ICleanableEventDispatcher> OnCleanupEvent { get; set; }
 40
 1141        public long parentId { get; set; }
 30442        public IList<long> childrenId { get; } = new List<long>();
 43
 44        const string MESH_GAMEOBJECT_NAME = "Mesh";
 45
 46        bool isReleased = false;
 47
 30448        public DecentralandEntity()
 49        {
 30450            meshesInfo = new MeshesInfo();
 85951            OnShapeUpdated += (entity) => meshesInfo.UpdateRenderersCollection();
 99352            meshesInfo.OnUpdated += () => OnMeshesInfoUpdated?.Invoke(this);
 47553            meshesInfo.OnCleanup += () => OnMeshesInfoCleaned?.Invoke(this);
 30454        }
 55
 56        public void AddChild(IDCLEntity entity)
 57        {
 2258            if (!children.ContainsKey(entity.entityId)) { children.Add(entity.entityId, entity); }
 1159        }
 60
 61        public void RemoveChild(IDCLEntity entity)
 62        {
 463            if (children.ContainsKey(entity.entityId)) { children.Remove(entity.entityId); }
 264        }
 65
 66        public void SetParent(IDCLEntity entity)
 67        {
 2168            if (parent != null) { parent.RemoveChild(this); }
 69
 1970            if (entity != null)
 71            {
 1172                parentId = entity.entityId;
 1173                entity.AddChild(this);
 74
 1175                if (entity.gameObject && gameObject)
 1176                    gameObject.transform.SetParent(entity.gameObject.transform, false);
 77            }
 1678            else if (gameObject) { gameObject.transform.SetParent(null, false); }
 79
 1980            parent = entity;
 1981        }
 82
 83        public void EnsureMeshGameObject(string gameObjectName = null)
 84        {
 25285            if (meshesInfo.meshRootGameObject != null) return;
 86
 24887            meshesInfo.meshRootGameObject = new GameObject { name = gameObjectName ?? MESH_GAMEOBJECT_NAME };
 24888            meshesInfo.meshRootGameObject.transform.SetParent(gameObject.transform);
 24889            meshesInfo.meshRootGameObject.transform.ResetLocalTRS();
 24890        }
 91
 92        public void ResetRelease()
 93        {
 094            isReleased = false;
 095        }
 96
 97        public void Cleanup()
 98        {
 99            // Don't do anything if this object was already released
 240100            if (isReleased)
 0101                return;
 102
 240103            OnRemoved?.Invoke(this);
 104
 105            // This will release the poolable objects of the mesh and the entity
 240106            OnCleanupEvent?.Invoke(this);
 107
 240108            scene.componentsManagerLegacy.CleanComponents(this);
 109
 240110            if (meshesInfo.meshRootGameObject && !meshesInfo.RootIsPoolableObject)
 111            {
 1112                Utils.SafeDestroy(meshesInfo.meshRootGameObject);
 1113                meshesInfo.CleanReferences();
 114            }
 115
 240116            if (gameObject)
 117            {
 238118                int childCount = gameObject.transform.childCount;
 119
 120                // Destroy any other children
 880121                for (var i = 0; i < childCount; i++)
 202122                    Utils.SafeDestroy(gameObject.transform.GetChild(i).gameObject);
 123
 124                //NOTE(Brian): This will prevent any component from storing/querying invalid gameObject references.
 238125                gameObject = null;
 126            }
 127
 240128            OnTransformChange = null;
 240129            isReleased = true;
 240130        }
 131
 132        public void UpdateInsideBoundariesStatus(bool isInsideBoundaries)
 133        {
 98134            isInsideSceneBoundaries = isInsideBoundaries;
 98135            OnInsideBoundariesChanged?.Invoke(this, isInsideSceneBoundaries);
 27136        }
 137
 138        public void UpdateOuterBoundariesStatus(bool isInsideOuterBoundaries)
 139        {
 262140            isInsideSceneOuterBoundaries = isInsideOuterBoundaries;
 262141            OnOuterBoundariesChanged?.Invoke(this, isInsideSceneOuterBoundaries);
 0142        }
 143    }
 144}

Methods/Properties

scene()
scene(DCL.Controllers.IParcelScene)
markedForCleanup()
markedForCleanup(System.Boolean)
isInsideSceneOuterBoundaries()
isInsideSceneOuterBoundaries(System.Boolean)
DecentralandEntity()
isInsideSceneBoundaries()
isInsideSceneBoundaries(System.Boolean)
children()
children(System.Collections.Generic.Dictionary[Int64,IDCLEntity])
parent()
parent(DCL.Models.IDCLEntity)
gameObject()
gameObject(UnityEngine.GameObject)
entityId()
entityId(System.Int64)
meshesInfo()
meshesInfo(DCL.Models.MeshesInfo)
meshRootGameObject()
renderers()
OnShapeUpdated()
OnShapeUpdated(System.Action[IDCLEntity])
OnShapeLoaded()
OnShapeLoaded(System.Action[IDCLEntity])
OnNameChange()
OnNameChange(System.Action[Object])
OnTransformChange()
OnTransformChange(System.Action[Vector3,Quaternion])
OnRemoved()
OnRemoved(System.Action[IDCLEntity])
OnMeshesInfoUpdated()
OnMeshesInfoUpdated(System.Action[IDCLEntity])
OnMeshesInfoCleaned()
OnMeshesInfoCleaned(System.Action[IDCLEntity])
OnBaseComponentAdded()
OnBaseComponentAdded(System.Action[CLASS_ID_COMPONENT,IDCLEntity])
OnInsideBoundariesChanged()
OnInsideBoundariesChanged(System.Action[IDCLEntity,Boolean])
OnOuterBoundariesChanged()
OnOuterBoundariesChanged(System.Action[IDCLEntity,Boolean])
OnCleanupEvent()
OnCleanupEvent(System.Action[ICleanableEventDispatcher])
parentId()
parentId(System.Int64)
childrenId()
AddChild(DCL.Models.IDCLEntity)
RemoveChild(DCL.Models.IDCLEntity)
SetParent(DCL.Models.IDCLEntity)
EnsureMeshGameObject(System.String)
ResetRelease()
Cleanup()
UpdateInsideBoundariesStatus(System.Boolean)
UpdateOuterBoundariesStatus(System.Boolean)