[Unity] EasyObjectPool modified, Make Pool Info at runtime.

APP 2020. 2. 12. 02:39

at line 113 

 

1
public PoolInfo[] poolInfo;
 

Changed to List

1
public List<PoolInfo> poolInfo;
 

 

at line 119 

1
2
3
4
5
6
7
8
void Start () {
            //set instance
            instance = this;
            //check for duplicate names
            CheckForDuplicatePoolNames();
            //create pools
            CreatePools();
        }
 

Start Changed

1
2
3
4
5
6
7
void Start()
        {
            //set instance
            instance = this;
            this.poolInfo = new List<PoolInfo>();
 
        }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

at line 127

 

Added New Method

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public void MakePoolInfo(string poolName, GameObject prefab, int poolSize = 5bool fixedSize = false)
        {
            PoolInfo poolInfo = new PoolInfo();
            poolInfo.poolName = poolName;
            poolInfo.prefab = prefab;
            poolInfo.poolSize = poolSize;
            poolInfo.fixedSize = fixedSize;
            this.poolInfo.Add(poolInfo);
            MakePool(poolInfo);
        }
        public void MakePool(PoolInfo poolInfo)
        {
            //check for duplicate names
            CheckForDuplicatePoolNames();
            //create pools
            CreatePool(poolInfo);
        }
        private void CreatePool(PoolInfo poolInfo)
        {
 
            Pool pool = new Pool(poolInfo.poolName, poolInfo.prefab,
                                 poolInfo.poolSize, poolInfo.fixedSize);
 
 
            Debug.Log("Creating pool: " + poolInfo.poolName);
            //add to mapping dict
            poolDictionary[poolInfo.poolName] = pool;
 
        }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

 

I did not consider duplicatePoolName.

So if you try to make PoolInfo with same name, it will stuck.

 

 

How To Use

 

1)On your script

 

1
using MarchingBytes;  
 

 

2)Just use this method where you want to make pool

 

1
EasyObjectPool.instance.MakePoolInfo( yourPoolName, yourGameObject);
 

 

 
: