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

public class GameObjectPool<T> where T : class
{
    short count;
    public delegate T Func();
    Func create_fn;
    Queue<T> objects;
    public GameObjectPool(short count, Func fn)
    {
        this.count = count;
        this.create_fn = fn;
        this.objects = new Queue<T>(this.count);
        allocate();
    }
    void allocate()
    {
        for (int i = 0; i < this.count; i++)
        {
            this.objects.Enqueue(this.create_fn());
        }
    }
    public T pop()
    {//dequeue 꺼내는 부분
        if (this.objects.Count <= 0)
        {
            allocate();
        }
        return this.objects.Dequeue();
    }
    public void push(T obj)
    {//enqueue 쌓는부분
        this.objects.Enqueue(obj);
    }
}


