Josip Å tajdohar

ObjectPoolerBase.cs PoolClasses.cs ObjectPooler.cs EnemyPooler.cs
The simplest implementation of the apstract class. It just makes itself a singelton object for ease of accses. While there are better coding models that don't use singelton constructs to find objects, this is self sufficient.

                using UnityEngine;
                using System.Collections;
                using System.Collections.Generic;
                
                namespace ObjectPooling
                {
                    /// <summary>
                    /// Object pooler class that creates pools of object based on the <see cref="ObjectPoolItem"/>
                    /// </summary>
                    public class ObjectPooler : ObjectPoolerBase<PoolType>
                    {
                        /// <summary>
                        /// The list of <see cref="ObjectPoolItem"/> for which i create pools for and populate those pools with desired objects.
                        /// </summary>
                        [SerializeField]
                        private List<ObjectPoolItem> objectPoolItems;
                
                        /// <summary>
                        /// The shared instance of this object.
                        /// </summary>
                        public static ObjectPooler SharedInstance;
                
                        /// <summary>
                        /// Storing the instance.
                        /// </summary>
                        private void Awake()
                        {
                            if (SharedInstance != null)
                            {
                                Debug.LogError("Multiple instances of ObjectPooler exist");
                            }
                
                            SharedInstance = this;
                
                            foreach (ObjectPoolItem objectPoolItem in objectPoolItems)
                            {
                                itemsToPool.Add(objectPoolItem);
                            }
                        }
                    }
                }