< Summary

Class:DCL.Models.DecentralandEntity
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/DecentralandEntity.cs
Covered lines:95
Uncovered lines:9
Coverable lines:104
Total lines:235
Line coverage:91.3% (95 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%12.212088.89%
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    {
 193614        public IParcelScene scene { get; set; }
 7115        public bool markedForCleanup { get; set; } = false;
 11016        public bool isInsideBoundaries { get; set; } = false;
 17
 194018        public Dictionary<string, IDCLEntity> children { get; private set; } = new Dictionary<string, IDCLEntity>();
 51519        public IDCLEntity parent { get; private set; }
 20
 275421        public Dictionary<CLASS_ID_COMPONENT, IEntityComponent> components { get; private set; } = new Dictionary<CLASS_
 184022        public Dictionary<System.Type, ISharedComponent> sharedComponents { get; private set; } = new Dictionary<System.
 23
 481124        public GameObject gameObject { get; set; }
 202925        public string entityId { get; set; }
 509326        public MeshesInfo meshesInfo { get; set; }
 301427        public GameObject meshRootGameObject => meshesInfo.meshRootGameObject;
 628        public Renderer[] renderers => meshesInfo.renderers;
 29
 142230        public System.Action<IDCLEntity> OnShapeUpdated { get; set; }
 12931        public System.Action<IDCLEntity> OnShapeLoaded { get; set; }
 21532        public System.Action<object> OnNameChange { get; set; }
 27333        public System.Action<object> OnTransformChange { get; set; }
 141434        public System.Action<IDCLEntity> OnRemoved { get; set; }
 035        public System.Action<IDCLEntity> OnMeshesInfoUpdated { get; set; }
 036        public System.Action<IDCLEntity> OnMeshesInfoCleaned { get; set; }
 37
 185838        public System.Action<ICleanableEventDispatcher> OnCleanupEvent { get; set; }
 39
 40        const string MESH_GAMEOBJECT_NAME = "Mesh";
 41
 42        bool isReleased = false;
 43
 173044        public DecentralandEntity()
 45        {
 173046            meshesInfo = new MeshesInfo();
 215147            OnShapeUpdated += (entity) => meshesInfo.UpdateRenderersCollection();
 236248            meshesInfo.OnUpdated += () => OnMeshesInfoUpdated?.Invoke(this);
 181049            meshesInfo.OnCleanup += () => OnMeshesInfoCleaned?.Invoke(this);
 173050        }
 51
 052        public Dictionary<System.Type, ISharedComponent> GetSharedComponents() { return sharedComponents; }
 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        {
 364            if (children.ContainsKey(entity.entityId))
 65            {
 366                children.Remove(entity.entityId);
 67            }
 368        }
 69
 70        public void SetParent(IDCLEntity entity)
 71        {
 1672            if (parent != null)
 73            {
 374                parent.RemoveChild(this);
 75            }
 76
 1677            if (entity != null)
 78            {
 1379                entity.AddChild(this);
 80
 1381                if (entity.gameObject && gameObject)
 1382                    gameObject.transform.SetParent(entity.gameObject.transform, false);
 1383            }
 384            else if (gameObject)
 85            {
 386                gameObject.transform.SetParent(null, false);
 87            }
 88
 1689            parent = entity;
 1690        }
 91
 92        public void EnsureMeshGameObject(string gameObjectName = null)
 93        {
 27794            if (meshesInfo.meshRootGameObject == null)
 95            {
 27596                meshesInfo.meshRootGameObject = new GameObject();
 27597                meshesInfo.meshRootGameObject.name = gameObjectName == null ? MESH_GAMEOBJECT_NAME : gameObjectName;
 27598                meshesInfo.meshRootGameObject.transform.SetParent(gameObject.transform);
 27599                Utils.ResetLocalTRS(meshesInfo.meshRootGameObject.transform);
 100            }
 277101        }
 102
 0103        public void ResetRelease() { isReleased = false; }
 104
 105        public void Cleanup()
 106        {
 107            // Don't do anything if this object was already released
 71108            if (isReleased)
 0109                return;
 110
 71111            OnRemoved?.Invoke(this);
 112
 113            // This will release the poolable objects of the mesh and the entity
 71114            OnCleanupEvent?.Invoke(this);
 115
 272116            foreach (var kvp in components)
 117            {
 65118                if (kvp.Value == null)
 119                    continue;
 120
 65121                if (kvp.Value is ICleanable cleanableComponent)
 65122                    cleanableComponent.Cleanup();
 123
 65124                if (!(kvp.Value is IPoolableObjectContainer poolableContainer))
 125                    continue;
 126
 4127                if (poolableContainer.poolableObject == null)
 128                    continue;
 129
 1130                poolableContainer.poolableObject.Release();
 131            }
 132
 71133            components.Clear();
 134
 71135            if (meshesInfo.meshRootGameObject)
 136            {
 0137                Utils.SafeDestroy(meshesInfo.meshRootGameObject);
 0138                meshesInfo.CleanReferences();
 139            }
 140
 71141            if (gameObject)
 142            {
 70143                int childCount = gameObject.transform.childCount;
 144
 145                // Destroy any other children
 266146                for (int i = 0; i < childCount; i++)
 147                {
 63148                    Utils.SafeDestroy(gameObject.transform.GetChild(i).gameObject);
 149                }
 150
 151                //NOTE(Brian): This will prevent any component from storing/querying invalid gameObject references.
 70152                gameObject = null;
 153            }
 154
 71155            OnTransformChange = null;
 71156            isReleased = true;
 71157        }
 158
 159        public void AddSharedComponent(System.Type componentType, ISharedComponent component)
 160        {
 450161            if (component == null)
 162            {
 0163                return;
 164            }
 165
 450166            RemoveSharedComponent(componentType);
 167
 450168            sharedComponents.Add(componentType, component);
 450169        }
 170
 171        public void RemoveSharedComponent(Type targetType, bool triggerDetaching = true)
 172        {
 682173            if (sharedComponents.TryGetValue(targetType, out ISharedComponent component))
 174            {
 159175                if (component == null)
 0176                    return;
 177
 159178                sharedComponents.Remove(targetType);
 179
 159180                if (triggerDetaching)
 31181                    component.DetachFrom(this, targetType);
 182            }
 682183        }
 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
 168195            T component = components.Values.FirstOrDefault(x => x is T) as T;
 196
 168197            if (component != null)
 1198                return component;
 199
 167200            component = sharedComponents.Values.FirstOrDefault(x => x is T) as T;
 201
 167202            if (component != null)
 48203                return component;
 204
 119205            return null;
 206        }
 207
 268208        public bool TryGetBaseComponent(CLASS_ID_COMPONENT componentId, out IEntityComponent component) { return compone
 209
 210        public bool TryGetSharedComponent(CLASS_ID componentId, out ISharedComponent component)
 211        {
 382212            foreach (KeyValuePair<Type, ISharedComponent> keyValuePairBaseDisposable in sharedComponents)
 213            {
 53214                if (keyValuePairBaseDisposable.Value.GetClassId() == (int) componentId)
 215                {
 10216                    component = keyValuePairBaseDisposable.Value;
 10217                    return true;
 218                }
 219            }
 220
 133221            component = null;
 133222            return false;
 10223        }
 224
 225        public ISharedComponent GetSharedComponent(System.Type targetType)
 226        {
 64227            if (sharedComponents.TryGetValue(targetType, out ISharedComponent component))
 228            {
 61229                return component;
 230            }
 231
 3232            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)