< 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:64
Uncovered lines:4
Coverable lines:68
Total lines:143
Line coverage:94.1% (64 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    {
 444512        public IParcelScene scene { get; set; }
 24613        public bool markedForCleanup { get; set; } = false;
 14
 15        // We let the SceneBoundsChecker update these values later
 106616        public bool isInsideSceneOuterBoundaries { get; set; } = true;
 179817        public bool isInsideSceneBoundaries { get; set; } = true;
 18
 88419        public Dictionary<long, IDCLEntity> children { get; private set; } = new Dictionary<long, IDCLEntity>();
 27720        public IDCLEntity parent { get; private set; }
 2180721        public GameObject gameObject { get; set; }
 663022        public long entityId { get; set; }
 7708923        public MeshesInfo meshesInfo { get; set; }
 403524        public GameObject meshRootGameObject => meshesInfo.meshRootGameObject;
 025        public Renderer[] renderers => meshesInfo.renderers;
 26
 27
 258828        public Action<IDCLEntity> OnShapeUpdated { get; set; }
 14629        public Action<IDCLEntity> OnShapeLoaded { get; set; }
 030        public Action<object> OnNameChange { get; set; }
 49231        public Action<object> OnTransformChange { get; set; }
 160732        public Action<IDCLEntity> OnRemoved { get; set; }
 71233        public Action<IDCLEntity> OnMeshesInfoUpdated { get; set; }
 18434        public Action<IDCLEntity> OnMeshesInfoCleaned { get; set; }
 26235        public Action<CLASS_ID_COMPONENT, IDCLEntity> OnBaseComponentAdded { get; set; }
 36
 336337        public Action<ICleanableEventDispatcher> OnCleanupEvent { get; set; }
 38
 2139        public long parentId { get; set; }
 31940        public IList<long> childrenId { get; } = new List<long>();
 41
 42        const string MESH_GAMEOBJECT_NAME = "Mesh";
 43
 44        bool isReleased = false;
 45
 31546        public DecentralandEntity()
 47        {
 31548            meshesInfo = new MeshesInfo();
 88649            OnShapeUpdated += (entity) => meshesInfo.UpdateRenderersCollection();
 102750            meshesInfo.OnUpdated += () => OnMeshesInfoUpdated?.Invoke(this);
 49951            meshesInfo.OnCleanup += () => OnMeshesInfoCleaned?.Invoke(this);
 31552        }
 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        {
 2372            if (parent != null)
 73            {
 274                parent.RemoveChild(this);
 75            }
 76
 2377            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            }
 1085            else if (gameObject)
 86            {
 1087                gameObject.transform.SetParent(null, false);
 88            }
 89
 2390            parent = entity;
 2391        }
 92
 93        public void EnsureMeshGameObject(string gameObjectName = null)
 94        {
 25995            if (meshesInfo.meshRootGameObject == null)
 96            {
 25797                meshesInfo.meshRootGameObject = new GameObject();
 25798                meshesInfo.meshRootGameObject.name = gameObjectName == null ? MESH_GAMEOBJECT_NAME : gameObjectName;
 25799                meshesInfo.meshRootGameObject.transform.SetParent(gameObject.transform);
 257100                Utils.ResetLocalTRS(meshesInfo.meshRootGameObject.transform);
 101            }
 259102        }
 103
 0104        public void ResetRelease() { isReleased = false; }
 105
 106        public void Cleanup()
 107        {
 108            // Don't do anything if this object was already released
 245109            if (isReleased)
 0110                return;
 111
 245112            OnRemoved?.Invoke(this);
 113
 114            // This will release the poolable objects of the mesh and the entity
 245115            OnCleanupEvent?.Invoke(this);
 116
 245117            scene.componentsManagerLegacy.CleanComponents(this);
 118
 245119            if (meshesInfo.meshRootGameObject)
 120            {
 8121                Utils.SafeDestroy(meshesInfo.meshRootGameObject);
 8122                meshesInfo.CleanReferences();
 123            }
 124
 245125            if (gameObject)
 126            {
 240127                int childCount = gameObject.transform.childCount;
 128
 129                // Destroy any other children
 1000130                for (int i = 0; i < childCount; i++)
 131                {
 260132                    Utils.SafeDestroy(gameObject.transform.GetChild(i).gameObject);
 133                }
 134
 135                //NOTE(Brian): This will prevent any component from storing/querying invalid gameObject references.
 240136                gameObject = null;
 137            }
 138
 245139            OnTransformChange = null;
 245140            isReleased = true;
 245141        }
 142    }
 143}