< 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:5
Coverable lines:69
Total lines:143
Line coverage:92.7% (64 of 69)
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    {
 587512        public IParcelScene scene { get; set; }
 52513        public bool markedForCleanup { get; set; } = false;
 14
 15        // We let the SceneBoundsChecker update these values later
 146616        public bool isInsideSceneOuterBoundaries { get; set; } = true;
 282717        public bool isInsideSceneBoundaries { get; set; } = true;
 18
 148719        public Dictionary<long, IDCLEntity> children { get; private set; } = new Dictionary<long, IDCLEntity>();
 50520        public IDCLEntity parent { get; private set; }
 543521        public GameObject gameObject { get; set; }
 1014722        public long entityId { get; set; }
 987423        public MeshesInfo meshesInfo { get; set; }
 450124        public GameObject meshRootGameObject => meshesInfo.meshRootGameObject;
 625        public Renderer[] renderers => meshesInfo.renderers;
 26
 27
 248128        public Action<IDCLEntity> OnShapeUpdated { get; set; }
 19329        public Action<IDCLEntity> OnShapeLoaded { get; set; }
 21330        public Action<object> OnNameChange { get; set; }
 28631        public Action<object> OnTransformChange { get; set; }
 191832        public Action<IDCLEntity> OnRemoved { get; set; }
 033        public Action<IDCLEntity> OnMeshesInfoUpdated { get; set; }
 034        public Action<IDCLEntity> OnMeshesInfoCleaned { get; set; }
 29635        public Action<CLASS_ID_COMPONENT, IDCLEntity> OnBaseComponentAdded { get; set; }
 36
 325037        public Action<ICleanableEventDispatcher> OnCleanupEvent { get; set; }
 38
 039        public long parentId { get; set; }
 60440        public IList<long> childrenId { get; } = new List<long>();
 41
 42        const string MESH_GAMEOBJECT_NAME = "Mesh";
 43
 44        bool isReleased = false;
 45
 60446        public DecentralandEntity()
 47        {
 60448            meshesInfo = new MeshesInfo();
 121649            OnShapeUpdated += (entity) => meshesInfo.UpdateRenderersCollection();
 137350            meshesInfo.OnUpdated += () => OnMeshesInfoUpdated?.Invoke(this);
 84651            meshesInfo.OnCleanup += () => OnMeshesInfoCleaned?.Invoke(this);
 60452        }
 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        {
 1872            if (parent != null)
 73            {
 274                parent.RemoveChild(this);
 75            }
 76
 1877            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);
 1384            }
 585            else if (gameObject)
 86            {
 587                gameObject.transform.SetParent(null, false);
 88            }
 89
 1890            parent = entity;
 1891        }
 92
 93        public void EnsureMeshGameObject(string gameObjectName = null)
 94        {
 28795            if (meshesInfo.meshRootGameObject == null)
 96            {
 28597                meshesInfo.meshRootGameObject = new GameObject();
 28598                meshesInfo.meshRootGameObject.name = gameObjectName == null ? MESH_GAMEOBJECT_NAME : gameObjectName;
 28599                meshesInfo.meshRootGameObject.transform.SetParent(gameObject.transform);
 285100                Utils.ResetLocalTRS(meshesInfo.meshRootGameObject.transform);
 101            }
 287102        }
 103
 0104        public void ResetRelease() { isReleased = false; }
 105
 106        public void Cleanup()
 107        {
 108            // Don't do anything if this object was already released
 534109            if (isReleased)
 0110                return;
 111
 534112            OnRemoved?.Invoke(this);
 113
 114            // This will release the poolable objects of the mesh and the entity
 534115            OnCleanupEvent?.Invoke(this);
 116
 534117            scene.componentsManagerLegacy.CleanComponents(this);
 118
 534119            if (meshesInfo.meshRootGameObject)
 120            {
 8121                Utils.SafeDestroy(meshesInfo.meshRootGameObject);
 8122                meshesInfo.CleanReferences();
 123            }
 124
 534125            if (gameObject)
 126            {
 529127                int childCount = gameObject.transform.childCount;
 128
 129                // Destroy any other children
 1622130                for (int i = 0; i < childCount; i++)
 131                {
 282132                    Utils.SafeDestroy(gameObject.transform.GetChild(i).gameObject);
 133                }
 134
 135                //NOTE(Brian): This will prevent any component from storing/querying invalid gameObject references.
 529136                gameObject = null;
 137            }
 138
 534139            OnTransformChange = null;
 534140            isReleased = true;
 534141        }
 142    }
 143}