Skip to content

Commit cf47821

Browse files
authored
Update Pool.cs
1 parent c7dd142 commit cf47821

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

Runtime/Pool.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ namespace ToolBox.Pools
66
public sealed class Pool
77
{
88
private Poolable _prefab = null;
9-
private int _currentCount = 0;
109
private Queue<Poolable> _entities = null;
1110

1211
private static Dictionary<int, Pool> _pools = new Dictionary<int, Pool>();
1312

1413
public Pool(Poolable prefab, int count)
1514
{
1615
_prefab = prefab;
17-
_currentCount = count;
1816
_entities = new Queue<Poolable>(count);
1917
_pools.Add(prefab.gameObject.GetHashCode(), this);
2018

@@ -32,7 +30,6 @@ public Pool(GameObject prefab, int count)
3230
_prefab.gameObject.SetActive(false);
3331
}
3432

35-
_currentCount = count;
3633
_entities = new Queue<Poolable>(count);
3734
_pools.Add(prefab.GetHashCode(), this);
3835

@@ -58,8 +55,6 @@ public void Populate(int count)
5855
_entities.Enqueue(entity);
5956
entity.gameObject.SetActive(false);
6057
}
61-
62-
_currentCount += count;
6358
}
6459

6560
public Poolable GetEntity()
@@ -120,7 +115,6 @@ public void ReturnEntity(Poolable entity)
120115
return;
121116

122117
_entities.Enqueue(entity);
123-
_currentCount++;
124118

125119
entity.transform.SetParent(null, false);
126120
entity.gameObject.SetActive(false);
@@ -130,7 +124,7 @@ private Poolable GetEntityFromPool()
130124
{
131125
Poolable entity;
132126

133-
if (_currentCount == 0)
127+
if (_entities.Count == 0)
134128
{
135129
entity = Object.Instantiate(_prefab);
136130
entity.SetPool(this);
@@ -145,11 +139,9 @@ private Poolable GetEntityFromPool()
145139
{
146140
entity = Object.Instantiate(_prefab);
147141
entity.SetPool(this);
148-
_currentCount++;
149142
}
150143

151144
entity.gameObject.SetActive(true);
152-
_currentCount--;
153145

154146
return entity;
155147
}

0 commit comments

Comments
 (0)