Skip to content

Commit f6a771c

Browse files
authored
Update Pool.cs
1 parent 3e332e4 commit f6a771c

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Pool.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using UnityEngine;
3+
using UnityEngine.InputSystem.Interactions;
34

45
namespace ToolBox.Pools
56
{
@@ -21,9 +22,6 @@ public Pool(Poolable prefab, int count)
2122
Populate(count);
2223
}
2324

24-
/// <summary>
25-
/// Prefab must contain Poolable component
26-
/// </summary>
2725
public Pool(GameObject prefab, int count)
2826
{
2927
_prefab = prefab.GetComponent<Poolable>();
@@ -53,6 +51,9 @@ public static Pool Get(GameObject prefab)
5351

5452
public void Populate(int count)
5553
{
54+
if (count <= 0)
55+
return;
56+
5657
for (int i = 0; i < count; i++)
5758
{
5859
Poolable entity = Object.Instantiate(_prefab);
@@ -66,15 +67,15 @@ public void Populate(int count)
6667

6768
public Poolable GetEntity()
6869
{
69-
Poolable entity = TakeEntity();
70+
Poolable entity = GetEntityFromPool();
7071
entity.ReturnFromPool();
7172

7273
return entity;
7374
}
7475

7576
public Poolable GetEntity(Transform parent, bool spawnInWorldSpace)
7677
{
77-
Poolable entity = TakeEntity();
78+
Poolable entity = GetEntityFromPool();
7879

7980
entity.transform.SetParent(parent, spawnInWorldSpace);
8081
entity.ReturnFromPool();
@@ -84,7 +85,7 @@ public Poolable GetEntity(Transform parent, bool spawnInWorldSpace)
8485

8586
public Poolable GetEntity(Vector3 position, Quaternion rotation)
8687
{
87-
Poolable entity = TakeEntity();
88+
Poolable entity = GetEntityFromPool();
8889

8990
entity.transform.SetPositionAndRotation(position, rotation);
9091
entity.ReturnFromPool();
@@ -94,7 +95,7 @@ public Poolable GetEntity(Vector3 position, Quaternion rotation)
9495

9596
public Poolable GetEntity(Vector3 position, Quaternion rotation, Transform parent, bool spawnInWorldSpace)
9697
{
97-
Poolable entity = TakeEntity();
98+
Poolable entity = GetEntityFromPool();
9899
Transform entityTransform = entity.transform;
99100

100101
entityTransform.SetParent(parent, spawnInWorldSpace);
@@ -128,14 +129,15 @@ public void ReturnEntity(Poolable entity)
128129
entity.gameObject.SetActive(false);
129130
}
130131

131-
private Poolable TakeEntity()
132+
private Poolable GetEntityFromPool()
132133
{
133134
Poolable entity;
134135

135136
if (_currentCount == 0)
136137
{
137138
entity = Object.Instantiate(_prefab);
138139
entity.SetPool(this);
140+
entity.gameObject.SetActive(true);
139141

140142
return entity;
141143
}

0 commit comments

Comments
 (0)