< 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:5
Coverable lines:33
Total lines:89
Line coverage:84.8% (28 of 33)
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%4.034087.5%
Release()0%3.333066.67%
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;
 1011        public GameObject gameObject { get; }
 12
 213        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
 75620        public PoolableObject(Pool poolOwner, GameObject go)
 21        {
 75622            this.gameObject = go;
 75623            this.pool = poolOwner;
 24
 75625            if (pool.useLifecycleHandlers)
 226                lifecycleHandlers = gameObject.GetComponents<IPoolLifecycleHandler>();
 75627        }
 28
 29        public void OnPoolGet()
 30        {
 79331            if (lifecycleHandlers != null)
 32            {
 1233                for (var i = 0; i < lifecycleHandlers.Length; i++)
 34                {
 435                    var handler = lifecycleHandlers[i];
 436                    handler.OnPoolGet();
 37                }
 38            }
 39
 79340            OnGet?.Invoke();
 041        }
 42
 43        public void OnPoolRelease()
 44        {
 78145            if (lifecycleHandlers != null)
 46            {
 1247                for (var i = 0; i < lifecycleHandlers.Length; i++)
 48                {
 449                    var handler = lifecycleHandlers[i];
 450                    handler.OnPoolRelease();
 51                }
 52            }
 53
 78154            OnRelease?.Invoke();
 055        }
 56
 57        public void Release()
 58        {
 78159            if (this == null)
 60            {
 61#if UNITY_EDITOR
 062                Debug.LogWarning("Release == null??! This shouldn't happen");
 63#endif
 064                return;
 65            }
 66
 78167            if (pool != null)
 68            {
 78169                pool.Release(this);
 78170            }
 71            else
 72            {
 73#if UNITY_EDITOR
 074                Debug.LogError("Pool is null upon release!");
 75#endif
 76            }
 77
 78178            OnPoolRelease();
 78179        }
 80
 481        public void RemoveFromPool() { pool.RemoveFromPool(this); }
 82
 83        public void OnCleanup(DCL.ICleanableEventDispatcher sender)
 84        {
 53185            sender.OnCleanupEvent -= this.OnCleanup;
 53186            Release();
 53187        }
 88    }
 89}