< Summary

Class:DCL.PoolableObject
Assembly:PoolManager
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/PoolManager/PoolableObject.cs
Covered lines:28
Uncovered lines:4
Coverable lines:32
Total lines:89
Line coverage:87.5% (28 of 32)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PoolableObject(...)0%220100%
OnPoolGet()0%4.034087.5%
OnPoolRelease()0%440100%
Release()0%3.473062.5%
RemoveFromPool()0%110100%
OnCleanup(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/PoolManager/PoolableObject.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using DCL.Components;
 3using UnityEngine;
 4
 5namespace DCL
 6{
 7    public class PoolableObject : IPoolableObject
 8    {
 9        public Pool pool;
 10        public LinkedListNode<PoolableObject> node;
 794011        public GameObject gameObject { get; }
 12
 713        public bool isInsidePool { get { return node != null; } }
 14
 15        public event System.Action OnGet;
 16        public event System.Action OnRelease;
 17
 18        private IPoolLifecycleHandler[] lifecycleHandlers = null;
 19
 147420        public PoolableObject(Pool poolOwner, GameObject go)
 21        {
 147422            this.gameObject = go;
 147423            this.pool = poolOwner;
 24
 147425            if (pool.useLifecycleHandlers)
 526                lifecycleHandlers = gameObject.GetComponents<IPoolLifecycleHandler>();
 147427        }
 28
 29        public void OnPoolGet()
 30        {
 156831            if (lifecycleHandlers != null)
 32            {
 3033                for (var i = 0; i < lifecycleHandlers.Length; i++)
 34                {
 1035                    var handler = lifecycleHandlers[i];
 1036                    handler.OnPoolGet();
 37                }
 38            }
 39
 156840            OnGet?.Invoke();
 041        }
 42
 43        private void OnPoolRelease()
 44        {
 172945            if (lifecycleHandlers != null)
 46            {
 3047                for (var i = 0; i < lifecycleHandlers.Length; i++)
 48                {
 1049                    var handler = lifecycleHandlers[i];
 1050                    handler.OnPoolRelease();
 51                }
 52            }
 53
 172954            OnRelease?.Invoke();
 155        }
 56
 57        public void Release()
 58        {
 172959            if (this == null)
 60            {
 61#if UNITY_EDITOR
 062                Debug.LogWarning("Release == null??! This shouldn't happen");
 63#endif
 064                return;
 65            }
 66
 172967            if (pool != null)
 68            {
 172969                pool.Release(this);
 70            }
 71            else
 72            {
 73#if UNITY_EDITOR
 074                Debug.LogError("Pool is null upon release!");
 75#endif
 76            }
 77
 172978            OnPoolRelease();
 172979        }
 80
 1081        public void RemoveFromPool() { pool.RemoveFromPool(this); }
 82
 83        public void OnCleanup(DCL.ICleanableEventDispatcher sender)
 84        {
 24385            sender.OnCleanupEvent -= this.OnCleanup;
 24386            Release();
 24387        }
 88    }
 89}