using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ObjectPool<T> where T : class
{
    private List<T> m_Pool;

    private Validation<T> m_Validator;
    private Generator<T> m_ObjectGenerator;

    public ObjectPool(Validation<T> inValidator, Generator<T> inGenerator)
    {
        m_Validator = inValidator;
        m_ObjectGenerator = inGenerator;

        m_Pool = new List<T>();
    }

    public T Get()
    {
        foreach(T obj in m_Pool)
        {
            if (m_Validator(obj))
                return obj;
        }

        T newObj = m_ObjectGenerator();

        m_Pool.Add(newObj);

        return newObj;
    }
}
