< Summary

Class:DCL.Models.DecentralandEntity
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/DecentralandEntity.cs
Covered lines:100
Uncovered lines:4
Coverable lines:104
Total lines:235
Line coverage:96.1% (100 of 104)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DecentralandEntity()0%110100%
GetSharedComponents()0%2100%
AddChild(...)0%220100%
RemoveChild(...)0%220100%
SetParent(...)0%660100%
EnsureMeshGameObject(...)0%440100%
ResetRelease()0%2100%
Cleanup()0%12120100%
AddSharedComponent(...)0%2.032080%
RemoveSharedComponent(...)0%4.054085.71%
TryGetComponent[T]()0%550100%
TryGetBaseComponent(...)0%110100%
TryGetSharedComponent(...)0%330100%
GetSharedComponent(...)0%220100%

File(s)

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

#LineLine coverage
 1using DCL.Components;
 2using DCL.Controllers;
 3using DCL.Helpers;
 4using System;
 5using System.Collections.Generic;
 6using System.Linq;
 7using UnityEngine;
 8
 9namespace DCL.Models
 10{
 11    [Serializable]
 12    public class DecentralandEntity : IDCLEntity
 13    {
 276314        public IParcelScene scene { get; set; }
 150815        public bool markedForCleanup { get; set; } = false;
 10816        public bool isInsideBoundaries { get; set; } = false;
 17
 149218        public Dictionary<string, IDCLEntity> children { get; private set; } = new Dictionary<string, IDCLEntity>();
 53919        public IDCLEntity parent { get; private set; }
 20
 171321        public Dictionary<CLASS_ID_COMPONENT, IEntityComponent> components { get; private set; } = new Dictionary<CLASS_
 99922        public Dictionary<System.Type, ISharedComponent> sharedComponents { get; private set; } = new Dictionary<System.
 23
 652824        public GameObject gameObject { get; set; }
 436825        public string entityId { get; set; }
 578326        public MeshesInfo meshesInfo { get; set; }
 405627        public GameObject meshRootGameObject => meshesInfo.meshRootGameObject;
 628        public Renderer[] renderers => meshesInfo.renderers;
 29
 137730        public System.Action<IDCLEntity> OnShapeUpdated { get; set; }
 14431        public System.Action<IDCLEntity> OnShapeLoaded { get; set; }
 26632        public System.Action<object> OnNameChange { get; set; }
 23233        public System.Action<object> OnTransformChange { get; set; }
 159634        public System.Action<IDCLEntity> OnRemoved { get; set; }
 116835        public System.Action<IDCLEntity> OnMeshesInfoUpdated { get; set; }
 116836        public System.Action<IDCLEntity> OnMeshesInfoCleaned { get; set; }
 37
 290638        public System.Action<ICleanableEventDispatcher> OnCleanupEvent { get; set; }
 39
 40        const string MESH_GAMEOBJECT_NAME = "Mesh";
 41
 42        bool isReleased = false;
 43
 79344        public DecentralandEntity()
 45        {
 79346            meshesInfo = new MeshesInfo();
 132747            OnShapeUpdated += (entity) => meshesInfo.UpdateRenderersCollection();
 134548            meshesInfo.OnUpdated += () => OnMeshesInfoUpdated?.Invoke(this);
 103249            meshesInfo.OnCleanup += () => OnMeshesInfoCleaned?.Invoke(this);
 79350        }
 51
 052        public Dictionary<System.Type, ISharedComponent> GetSharedComponents() { return sharedComponents; }
 53
 54        public void AddChild(IDCLEntity entity)
 55        {
 1256            if (!children.ContainsKey(entity.entityId))
 57            {
 1258                children.Add(entity.entityId, entity);
 59            }
 1260        }
 61
 62        public void RemoveChild(IDCLEntity entity)
 63        {
 1164            if (children.ContainsKey(entity.entityId))
 65            {
 1166                children.Remove(entity.entityId);
 67            }
 1168        }
 69
 70        public void SetParent(IDCLEntity entity)
 71        {
 50772            if (parent != null)
 73            {
 1174                parent.RemoveChild(this);
 75            }
 76
 50777            if (entity != null)
 78            {
 1279                entity.AddChild(this);
 80
 1281                if (entity.gameObject && gameObject)
 1282                    gameObject.transform.SetParent(entity.gameObject.transform, false);
 1283            }
 49584            else if (gameObject)
 85            {
 49186                gameObject.transform.SetParent(null, false);
 87            }
 88
 50789            parent = entity;
 50790        }
 91
 92        public void EnsureMeshGameObject(string gameObjectName = null)
 93        {
 22594            if (meshesInfo.meshRootGameObject == null)
 95            {
 22396                meshesInfo.meshRootGameObject = new GameObject();
 22397                meshesInfo.meshRootGameObject.name = gameObjectName == null ? MESH_GAMEOBJECT_NAME : gameObjectName;
 22398                meshesInfo.meshRootGameObject.transform.SetParent(gameObject.transform);
 22399                Utils.ResetLocalTRS(meshesInfo.meshRootGameObject.transform);
 100            }
 225101        }
 102
 0103        public void ResetRelease() { isReleased = false; }
 104
 105        public void Cleanup()
 106        {
 107            // Don't do anything if this object was already released
 533108            if (isReleased)
 1109                return;
 110
 532111            OnRemoved?.Invoke(this);
 112
 113            // This will release the poolable objects of the mesh and the entity
 532114            OnCleanupEvent?.Invoke(this);
 115
 1530116            foreach (var kvp in components)
 117            {
 233118                if (kvp.Value == null)
 119                    continue;
 120
 233121                if (kvp.Value is ICleanable cleanableComponent)
 233122                    cleanableComponent.Cleanup();
 123
 233124                if (!(kvp.Value is IPoolableObjectContainer poolableContainer))
 125                    continue;
 126
 65127                if (poolableContainer.poolableObject == null)
 128                    continue;
 129
 2130                poolableContainer.poolableObject.Release();
 131            }
 132
 532133            components.Clear();
 134
 532135            if (meshesInfo.meshRootGameObject)
 136            {
 8137                Utils.SafeDestroy(meshesInfo.meshRootGameObject);
 8138                meshesInfo.CleanReferences();
 139            }
 140
 532141            if (gameObject)
 142            {
 528143                int childCount = gameObject.transform.childCount;
 144
 145                // Destroy any other children
 1628146                for (int i = 0; i < childCount; i++)
 147                {
 286148                    Utils.SafeDestroy(gameObject.transform.GetChild(i).gameObject);
 149                }
 150
 151                //NOTE(Brian): This will prevent any component from storing/querying invalid gameObject references.
 528152                gameObject = null;
 153            }
 154
 532155            OnTransformChange = null;
 532156            isReleased = true;
 532157        }
 158
 159        public void AddSharedComponent(System.Type componentType, ISharedComponent component)
 160        {
 346161            if (component == null)
 162            {
 0163                return;
 164            }
 165
 346166            RemoveSharedComponent(componentType);
 167
 346168            sharedComponents.Add(componentType, component);
 346169        }
 170
 171        public void RemoveSharedComponent(Type targetType, bool triggerDetaching = true)
 172        {
 731173            if (sharedComponents.TryGetValue(targetType, out ISharedComponent component))
 174            {
 339175                if (component == null)
 0176                    return;
 177
 339178                sharedComponents.Remove(targetType);
 179
 339180                if (triggerDetaching)
 16181                    component.DetachFrom(this, targetType);
 182            }
 731183        }
 184
 185        /// <summary>
 186        /// This function is designed to get interfaces implemented by diverse components.
 187        ///
 188        /// If you want to get the component itself please use TryGetBaseComponent or TryGetSharedComponent.
 189        /// </summary>
 190        /// <typeparam name="T"></typeparam>
 191        /// <returns></returns>
 192        public T TryGetComponent<T>() where T : class
 193        {
 194            //Note (Adrian): If you are going to call this function frequently, please refactor it to avoid using LinQ f
 237195            T component = components.Values.FirstOrDefault(x => x is T) as T;
 196
 237197            if (component != null)
 1198                return component;
 199
 236200            component = sharedComponents.Values.FirstOrDefault(x => x is T) as T;
 201
 236202            if (component != null)
 53203                return component;
 204
 183205            return null;
 206        }
 207
 4208        public bool TryGetBaseComponent(CLASS_ID_COMPONENT componentId, out IEntityComponent component) { return compone
 209
 210        public bool TryGetSharedComponent(CLASS_ID componentId, out ISharedComponent component)
 211        {
 472212            foreach (KeyValuePair<Type, ISharedComponent> keyValuePairBaseDisposable in sharedComponents)
 213            {
 85214                if (keyValuePairBaseDisposable.Value.GetClassId() == (int) componentId)
 215                {
 40216                    component = keyValuePairBaseDisposable.Value;
 40217                    return true;
 218                }
 219            }
 220
 131221            component = null;
 131222            return false;
 40223        }
 224
 225        public ISharedComponent GetSharedComponent(System.Type targetType)
 226        {
 64227            if (sharedComponents.TryGetValue(targetType, out ISharedComponent component))
 228            {
 56229                return component;
 230            }
 231
 8232            return null;
 233        }
 234    }
 235}

Methods/Properties

scene()
scene(DCL.Controllers.IParcelScene)
markedForCleanup()
markedForCleanup(System.Boolean)
isInsideBoundaries()
isInsideBoundaries(System.Boolean)
children()
children(System.Collections.Generic.Dictionary[String,IDCLEntity])
DecentralandEntity()
parent()
parent(DCL.Models.IDCLEntity)
components()
components(System.Collections.Generic.Dictionary[CLASS_ID_COMPONENT,IEntityComponent])
sharedComponents()
sharedComponents(System.Collections.Generic.Dictionary[Type,ISharedComponent])
gameObject()
gameObject(UnityEngine.GameObject)
entityId()
entityId(System.String)
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[Object])
OnRemoved()
OnRemoved(System.Action[IDCLEntity])
OnMeshesInfoUpdated()
OnMeshesInfoUpdated(System.Action[IDCLEntity])
OnMeshesInfoCleaned()
OnMeshesInfoCleaned(System.Action[IDCLEntity])
OnCleanupEvent()
OnCleanupEvent(System.Action[ICleanableEventDispatcher])
GetSharedComponents()
AddChild(DCL.Models.IDCLEntity)
RemoveChild(DCL.Models.IDCLEntity)
SetParent(DCL.Models.IDCLEntity)
EnsureMeshGameObject(System.String)
ResetRelease()
Cleanup()
AddSharedComponent(System.Type, DCL.Components.ISharedComponent)
RemoveSharedComponent(System.Type, System.Boolean)
TryGetComponent[T]()
TryGetBaseComponent(DCL.Models.CLASS_ID_COMPONENT, DCL.Components.IEntityComponent&)
TryGetSharedComponent(DCL.Models.CLASS_ID, DCL.Components.ISharedComponent&)
GetSharedComponent(System.Type)