< Summary

Class:DCL.Models.DecentralandEntity
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/DecentralandEntity.cs
Covered lines:98
Uncovered lines:5
Coverable lines:103
Total lines:234
Line coverage:95.1% (98 of 103)
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%2.152066.67%

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    {
 141714        public IParcelScene scene { get; set; }
 151215        public bool markedForCleanup { get; set; } = false;
 11816        public bool isInsideBoundaries { get; set; } = false;
 17
 149118        public Dictionary<string, IDCLEntity> children { get; private set; } = new Dictionary<string, IDCLEntity>();
 54019        public IDCLEntity parent { get; private set; }
 20
 168921        public Dictionary<CLASS_ID_COMPONENT, IEntityComponent> components { get; private set; } = new Dictionary<CLASS_
 98122        public Dictionary<System.Type, ISharedComponent> sharedComponents { get; private set; } = new Dictionary<System.
 23
 605324        public GameObject gameObject { get; set; }
 184125        public string entityId { get; set; }
 586326        public MeshesInfo meshesInfo { get; set; }
 379727        public GameObject meshRootGameObject => meshesInfo.meshRootGameObject;
 628        public Renderer[] renderers => meshesInfo.renderers;
 29
 140430        public System.Action<IDCLEntity> OnShapeUpdated { get; set; }
 26931        public System.Action<object> OnNameChange { get; set; }
 22732        public System.Action<object> OnTransformChange { get; set; }
 159433        public System.Action<IDCLEntity> OnRemoved { get; set; }
 115634        public System.Action<IDCLEntity> OnMeshesInfoUpdated { get; set; }
 115635        public System.Action<IDCLEntity> OnMeshesInfoCleaned { get; set; }
 36
 283037        public System.Action<ICleanableEventDispatcher> OnCleanupEvent { get; set; }
 38
 39        const string MESH_GAMEOBJECT_NAME = "Mesh";
 40
 41        bool isReleased = false;
 42
 78943        public DecentralandEntity()
 44        {
 78945            meshesInfo = new MeshesInfo();
 131246            OnShapeUpdated += (entity) => meshesInfo.UpdateRenderersCollection();
 132747            meshesInfo.OnUpdated += () => OnMeshesInfoUpdated?.Invoke(this);
 102748            meshesInfo.OnCleanup += () => OnMeshesInfoCleaned?.Invoke(this);
 78949        }
 50
 051        public Dictionary<System.Type, ISharedComponent> GetSharedComponents() { return sharedComponents; }
 52
 53        public void AddChild(IDCLEntity entity)
 54        {
 1255            if (!children.ContainsKey(entity.entityId))
 56            {
 1257                children.Add(entity.entityId, entity);
 58            }
 1259        }
 60
 61        public void RemoveChild(IDCLEntity entity)
 62        {
 1163            if (children.ContainsKey(entity.entityId))
 64            {
 1165                children.Remove(entity.entityId);
 66            }
 1167        }
 68
 69        public void SetParent(IDCLEntity entity)
 70        {
 51071            if (parent != null)
 72            {
 1173                parent.RemoveChild(this);
 74            }
 75
 51076            if (entity != null)
 77            {
 1278                entity.AddChild(this);
 79
 1280                if (entity.gameObject && gameObject)
 1281                    gameObject.transform.SetParent(entity.gameObject.transform, false);
 1282            }
 49883            else if (gameObject)
 84            {
 49485                gameObject.transform.SetParent(null, false);
 86            }
 87
 51088            parent = entity;
 51089        }
 90
 91        public void EnsureMeshGameObject(string gameObjectName = null)
 92        {
 22393            if (meshesInfo.meshRootGameObject == null)
 94            {
 22195                meshesInfo.meshRootGameObject = new GameObject();
 22196                meshesInfo.meshRootGameObject.name = gameObjectName == null ? MESH_GAMEOBJECT_NAME : gameObjectName;
 22197                meshesInfo.meshRootGameObject.transform.SetParent(gameObject.transform);
 22198                Utils.ResetLocalTRS(meshesInfo.meshRootGameObject.transform);
 99            }
 223100        }
 101
 0102        public void ResetRelease() { isReleased = false; }
 103
 104        public void Cleanup()
 105        {
 106            // Don't do anything if this object was already released
 531107            if (isReleased)
 1108                return;
 109
 530110            OnRemoved?.Invoke(this);
 111
 112            // This will release the poolable objects of the mesh and the entity
 530113            OnCleanupEvent?.Invoke(this);
 114
 1518115            foreach (var kvp in components)
 116            {
 229117                if (kvp.Value == null)
 118                    continue;
 119
 229120                if (kvp.Value is ICleanable cleanableComponent)
 229121                    cleanableComponent.Cleanup();
 122
 229123                if (!(kvp.Value is IPoolableObjectContainer poolableContainer))
 124                    continue;
 125
 63126                if (poolableContainer.poolableObject == null)
 127                    continue;
 128
 1129                poolableContainer.poolableObject.Release();
 130            }
 131
 530132            components.Clear();
 133
 530134            if (meshesInfo.meshRootGameObject)
 135            {
 8136                Utils.SafeDestroy(meshesInfo.meshRootGameObject);
 8137                meshesInfo.CleanReferences();
 138            }
 139
 530140            if (gameObject)
 141            {
 526142                int childCount = gameObject.transform.childCount;
 143
 144                // Destroy any other children
 1624145                for (int i = 0; i < childCount; i++)
 146                {
 286147                    Utils.SafeDestroy(gameObject.transform.GetChild(i).gameObject);
 148                }
 149
 150                //NOTE(Brian): This will prevent any component from storing/querying invalid gameObject references.
 526151                gameObject = null;
 152            }
 153
 530154            OnTransformChange = null;
 530155            isReleased = true;
 530156        }
 157
 158        public void AddSharedComponent(System.Type componentType, ISharedComponent component)
 159        {
 344160            if (component == null)
 161            {
 0162                return;
 163            }
 164
 344165            RemoveSharedComponent(componentType);
 166
 344167            sharedComponents.Add(componentType, component);
 344168        }
 169
 170        public void RemoveSharedComponent(Type targetType, bool triggerDetaching = true)
 171        {
 729172            if (sharedComponents.TryGetValue(targetType, out ISharedComponent component))
 173            {
 339174                if (component == null)
 0175                    return;
 176
 339177                sharedComponents.Remove(targetType);
 178
 339179                if (triggerDetaching)
 15180                    component.DetachFrom(this, targetType);
 181            }
 729182        }
 183
 184        /// <summary>
 185        /// This function is designed to get interfaces implemented by diverse components.
 186        ///
 187        /// If you want to get the component itself please use TryGetBaseComponent or TryGetSharedComponent.
 188        /// </summary>
 189        /// <typeparam name="T"></typeparam>
 190        /// <returns></returns>
 191        public T TryGetComponent<T>() where T : class
 192        {
 193            //Note (Adrian): If you are going to call this function frequently, please refactor it to avoid using LinQ f
 245194            T component = components.Values.FirstOrDefault(x => x is T) as T;
 195
 245196            if (component != null)
 1197                return component;
 198
 244199            component = sharedComponents.Values.FirstOrDefault(x => x is T) as T;
 200
 244201            if (component != null)
 48202                return component;
 203
 196204            return null;
 205        }
 206
 4207        public bool TryGetBaseComponent(CLASS_ID_COMPONENT componentId, out IEntityComponent component) { return compone
 208
 209        public bool TryGetSharedComponent(CLASS_ID componentId, out ISharedComponent component)
 210        {
 480211            foreach (KeyValuePair<Type, ISharedComponent> keyValuePairBaseDisposable in sharedComponents)
 212            {
 87213                if (keyValuePairBaseDisposable.Value.GetClassId() == (int) componentId)
 214                {
 42215                    component = keyValuePairBaseDisposable.Value;
 42216                    return true;
 217                }
 218            }
 219
 132220            component = null;
 132221            return false;
 42222        }
 223
 224        public ISharedComponent GetSharedComponent(System.Type targetType)
 225        {
 42226            if (sharedComponents.TryGetValue(targetType, out ISharedComponent component))
 227            {
 42228                return component;
 229            }
 230
 0231            return null;
 232        }
 233    }
 234}

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])
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)