< 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
 80620        public PoolableObject(Pool poolOwner, GameObject go)
 21        {
 80622            this.gameObject = go;
 80623            this.pool = poolOwner;
 24
 80625            if (pool.useLifecycleHandlers)
 226                lifecycleHandlers = gameObject.GetComponents<IPoolLifecycleHandler>();
 80627        }
 28
 29        public void OnPoolGet()
 30        {
 85231            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
 85240            OnGet?.Invoke();
 041        }
 42
 43        public void OnPoolRelease()
 44        {
 84345            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
 84354            OnRelease?.Invoke();
 055        }
 56
 57        public void Release()
 58        {
 84359            if (this == null)
 60            {
 61#if UNITY_EDITOR
 062                Debug.LogWarning("Release == null??! This shouldn't happen");
 63#endif
 064                return;
 65            }
 66
 84367            if (pool != null)
 68            {
 84369                pool.Release(this);
 84370            }
 71            else
 72            {
 73#if UNITY_EDITOR
 074                Debug.LogError("Pool is null upon release!");
 75#endif
 76            }
 77
 84378            OnPoolRelease();
 84379        }
 80
 481        public void RemoveFromPool() { pool.RemoveFromPool(this); }
 82
 83        public void OnCleanup(DCL.ICleanableEventDispatcher sender)
 84        {
 7085            sender.OnCleanupEvent -= this.OnCleanup;
 7086            Release();
 7087        }
 88    }
 89}