< 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:2
Coverable lines:68
Total lines:143
Line coverage:97% (66 of 68)
Covered branches:0
Total branches:0

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%440100%
ResetRelease()0%2100%
Cleanup()0%7.017094.44%

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    {
 450712        public IParcelScene scene { get; set; }
 24413        public bool markedForCleanup { get; set; } = false;
 14
 15        // We let the SceneBoundsChecker update these values later
 104916        public bool isInsideSceneOuterBoundaries { get; set; } = true;
 181817        public bool isInsideSceneBoundaries { get; set; } = true;
 18
 88519        public Dictionary<long, IDCLEntity> children { get; private set; } = new Dictionary<long, IDCLEntity>();
 27320        public IDCLEntity parent { get; private set; }
 2048621        public GameObject gameObject { get; set; }
 660722        public long entityId { get; set; }
 7114723        public MeshesInfo meshesInfo { get; set; }
 410424        public GameObject meshRootGameObject => meshesInfo.meshRootGameObject;
 325        public Renderer[] renderers => meshesInfo.renderers;
 26
 27
 263428        public Action<IDCLEntity> OnShapeUpdated { get; set; }
 15029        public Action<IDCLEntity> OnShapeLoaded { get; set; }
 830        public Action<object> OnNameChange { get; set; }
 50731        public Action<object> OnTransformChange { get; set; }
 161732        public Action<IDCLEntity> OnRemoved { get; set; }
 72633        public Action<IDCLEntity> OnMeshesInfoUpdated { get; set; }
 22034        public Action<IDCLEntity> OnMeshesInfoCleaned { get; set; }
 26535        public Action<CLASS_ID_COMPONENT, IDCLEntity> OnBaseComponentAdded { get; set; }
 36
 341537        public Action<ICleanableEventDispatcher> OnCleanupEvent { get; set; }
 38
 1339        public long parentId { get; set; }
 31740        public IList<long> childrenId { get; } = new List<long>();
 41
 42        const string MESH_GAMEOBJECT_NAME = "Mesh";
 43
 44        bool isReleased = false;
 45
 31746        public DecentralandEntity()
 47        {
 31748            meshesInfo = new MeshesInfo();
 89849            OnShapeUpdated += (entity) => meshesInfo.UpdateRenderersCollection();
 104350            meshesInfo.OnUpdated += () => OnMeshesInfoUpdated?.Invoke(this);
 53751            meshesInfo.OnCleanup += () => OnMeshesInfoCleaned?.Invoke(this);
 31752        }
 53
 54        public void AddChild(IDCLEntity entity)
 55        {
 1356            if (!children.ContainsKey(entity.entityId))
 57            {
 1358                children.Add(entity.entityId, entity);
 59            }
 1360        }
 61
 62        public void RemoveChild(IDCLEntity entity)
 63        {
 264            if (children.ContainsKey(entity.entityId))
 65            {
 266                children.Remove(entity.entityId);
 67            }
 268        }
 69
 70        public void SetParent(IDCLEntity entity)
 71        {
 2072            if (parent != null)
 73            {
 274                parent.RemoveChild(this);
 75            }
 76
 2077            if (entity != null)
 78            {
 1379                parentId = entity.entityId;
 1380                entity.AddChild(this);
 81
 1382                if (entity.gameObject && gameObject)
 1383                    gameObject.transform.SetParent(entity.gameObject.transform, false);
 84            }
 785            else if (gameObject)
 86            {
 787                gameObject.transform.SetParent(null, false);
 88            }
 89
 2090            parent = entity;
 2091        }
 92
 93        public void EnsureMeshGameObject(string gameObjectName = null)
 94        {
 26495            if (meshesInfo.meshRootGameObject == null)
 96            {
 26297                meshesInfo.meshRootGameObject = new GameObject();
 26298                meshesInfo.meshRootGameObject.name = gameObjectName == null ? MESH_GAMEOBJECT_NAME : gameObjectName;
 26299                meshesInfo.meshRootGameObject.transform.SetParent(gameObject.transform);
 262100                Utils.ResetLocalTRS(meshesInfo.meshRootGameObject.transform);
 101            }
 264102        }
 103
 0104        public void ResetRelease() { isReleased = false; }
 105
 106        public void Cleanup()
 107        {
 108            // Don't do anything if this object was already released
 249109            if (isReleased)
 0110                return;
 111
 249112            OnRemoved?.Invoke(this);
 113
 114            // This will release the poolable objects of the mesh and the entity
 249115            OnCleanupEvent?.Invoke(this);
 116
 249117            scene.componentsManagerLegacy.CleanComponents(this);
 118
 249119            if (meshesInfo.meshRootGameObject)
 120            {
 8121                Utils.SafeDestroy(meshesInfo.meshRootGameObject);
 8122                meshesInfo.CleanReferences();
 123            }
 124
 249125            if (gameObject)
 126            {
 244127                int childCount = gameObject.transform.childCount;
 128
 129                // Destroy any other children
 1018130                for (int i = 0; i < childCount; i++)
 131                {
 265132                    Utils.SafeDestroy(gameObject.transform.GetChild(i).gameObject);
 133                }
 134
 135                //NOTE(Brian): This will prevent any component from storing/querying invalid gameObject references.
 244136                gameObject = null;
 137            }
 138
 249139            OnTransformChange = null;
 249140            isReleased = true;
 249141        }
 142    }
 143}