< 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:61
Uncovered lines:5
Coverable lines:66
Total lines:137
Line coverage:92.4% (61 of 66)
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    {
 284412        public IParcelScene scene { get; set; }
 52213        public bool markedForCleanup { get; set; } = false;
 10314        public bool isInsideBoundaries { get; set; } = false;
 15
 126216        public Dictionary<long, IDCLEntity> children { get; private set; } = new Dictionary<long, IDCLEntity>();
 51417        public IDCLEntity parent { get; private set; }
 610318        public GameObject gameObject { get; set; }
 994819        public long entityId { get; set; }
 957720        public MeshesInfo meshesInfo { get; set; }
 379321        public GameObject meshRootGameObject => meshesInfo.meshRootGameObject;
 622        public Renderer[] renderers => meshesInfo.renderers;
 23
 246124        public Action<IDCLEntity> OnShapeUpdated { get; set; }
 18825        public Action<IDCLEntity> OnShapeLoaded { get; set; }
 21326        public Action<object> OnNameChange { get; set; }
 28527        public Action<object> OnTransformChange { get; set; }
 190628        public Action<IDCLEntity> OnRemoved { get; set; }
 029        public Action<IDCLEntity> OnMeshesInfoUpdated { get; set; }
 030        public Action<IDCLEntity> OnMeshesInfoCleaned { get; set; }
 31
 319032        public Action<ICleanableEventDispatcher> OnCleanupEvent { get; set; }
 33
 034        public long parentId { get; set; }
 35
 36        const string MESH_GAMEOBJECT_NAME = "Mesh";
 37
 38        bool isReleased = false;
 39
 60040        public DecentralandEntity()
 41        {
 60042            meshesInfo = new MeshesInfo();
 120643            OnShapeUpdated += (entity) => meshesInfo.UpdateRenderersCollection();
 136144            meshesInfo.OnUpdated += () => OnMeshesInfoUpdated?.Invoke(this);
 83945            meshesInfo.OnCleanup += () => OnMeshesInfoCleaned?.Invoke(this);
 60046        }
 47
 48        public void AddChild(IDCLEntity entity)
 49        {
 1250            if (!children.ContainsKey(entity.entityId))
 51            {
 1252                children.Add(entity.entityId, entity);
 53            }
 1254        }
 55
 56        public void RemoveChild(IDCLEntity entity)
 57        {
 258            if (children.ContainsKey(entity.entityId))
 59            {
 260                children.Remove(entity.entityId);
 61            }
 262        }
 63
 64        public void SetParent(IDCLEntity entity)
 65        {
 1766            if (parent != null)
 67            {
 268                parent.RemoveChild(this);
 69            }
 70
 1771            if (entity != null)
 72            {
 1273                parentId = entity.entityId;
 1274                entity.AddChild(this);
 75
 1276                if (entity.gameObject && gameObject)
 1277                    gameObject.transform.SetParent(entity.gameObject.transform, false);
 1278            }
 579            else if (gameObject)
 80            {
 581                gameObject.transform.SetParent(null, false);
 82            }
 83
 1784            parent = entity;
 1785        }
 86
 87        public void EnsureMeshGameObject(string gameObjectName = null)
 88        {
 28489            if (meshesInfo.meshRootGameObject == null)
 90            {
 28291                meshesInfo.meshRootGameObject = new GameObject();
 28292                meshesInfo.meshRootGameObject.name = gameObjectName == null ? MESH_GAMEOBJECT_NAME : gameObjectName;
 28293                meshesInfo.meshRootGameObject.transform.SetParent(gameObject.transform);
 28294                Utils.ResetLocalTRS(meshesInfo.meshRootGameObject.transform);
 95            }
 28496        }
 97
 098        public void ResetRelease() { isReleased = false; }
 99
 100        public void Cleanup()
 101        {
 102            // Don't do anything if this object was already released
 530103            if (isReleased)
 0104                return;
 105
 530106            OnRemoved?.Invoke(this);
 107
 108            // This will release the poolable objects of the mesh and the entity
 530109            OnCleanupEvent?.Invoke(this);
 110
 530111            scene.componentsManagerLegacy.CleanComponents(this);
 112
 530113            if (meshesInfo.meshRootGameObject)
 114            {
 8115                Utils.SafeDestroy(meshesInfo.meshRootGameObject);
 8116                meshesInfo.CleanReferences();
 117            }
 118
 530119            if (gameObject)
 120            {
 525121                int childCount = gameObject.transform.childCount;
 122
 123                // Destroy any other children
 1580124                for (int i = 0; i < childCount; i++)
 125                {
 265126                    Utils.SafeDestroy(gameObject.transform.GetChild(i).gameObject);
 127                }
 128
 129                //NOTE(Brian): This will prevent any component from storing/querying invalid gameObject references.
 525130                gameObject = null;
 131            }
 132
 530133            OnTransformChange = null;
 530134            isReleased = true;
 530135        }
 136    }
 137}