1
- using System . Collections . Generic ;
1
+ using System . Collections . Generic ;
2
2
using UnityEngine ;
3
+ using UnityEngine . InputSystem . Interactions ;
3
4
4
5
namespace ToolBox . Pools
5
6
{
@@ -21,9 +22,6 @@ public Pool(Poolable prefab, int count)
21
22
Populate ( count ) ;
22
23
}
23
24
24
- /// <summary>
25
- /// Prefab must contain Poolable component
26
- /// </summary>
27
25
public Pool ( GameObject prefab , int count )
28
26
{
29
27
_prefab = prefab . GetComponent < Poolable > ( ) ;
@@ -53,6 +51,9 @@ public static Pool Get(GameObject prefab)
53
51
54
52
public void Populate ( int count )
55
53
{
54
+ if ( count <= 0 )
55
+ return ;
56
+
56
57
for ( int i = 0 ; i < count ; i ++ )
57
58
{
58
59
Poolable entity = Object . Instantiate ( _prefab ) ;
@@ -66,15 +67,15 @@ public void Populate(int count)
66
67
67
68
public Poolable GetEntity ( )
68
69
{
69
- Poolable entity = TakeEntity ( ) ;
70
+ Poolable entity = GetEntityFromPool ( ) ;
70
71
entity . ReturnFromPool ( ) ;
71
72
72
73
return entity ;
73
74
}
74
75
75
76
public Poolable GetEntity ( Transform parent , bool spawnInWorldSpace )
76
77
{
77
- Poolable entity = TakeEntity ( ) ;
78
+ Poolable entity = GetEntityFromPool ( ) ;
78
79
79
80
entity . transform . SetParent ( parent , spawnInWorldSpace ) ;
80
81
entity . ReturnFromPool ( ) ;
@@ -84,7 +85,7 @@ public Poolable GetEntity(Transform parent, bool spawnInWorldSpace)
84
85
85
86
public Poolable GetEntity ( Vector3 position , Quaternion rotation )
86
87
{
87
- Poolable entity = TakeEntity ( ) ;
88
+ Poolable entity = GetEntityFromPool ( ) ;
88
89
89
90
entity . transform . SetPositionAndRotation ( position , rotation ) ;
90
91
entity . ReturnFromPool ( ) ;
@@ -94,7 +95,7 @@ public Poolable GetEntity(Vector3 position, Quaternion rotation)
94
95
95
96
public Poolable GetEntity ( Vector3 position , Quaternion rotation , Transform parent , bool spawnInWorldSpace )
96
97
{
97
- Poolable entity = TakeEntity ( ) ;
98
+ Poolable entity = GetEntityFromPool ( ) ;
98
99
Transform entityTransform = entity . transform ;
99
100
100
101
entityTransform . SetParent ( parent , spawnInWorldSpace ) ;
@@ -128,14 +129,15 @@ public void ReturnEntity(Poolable entity)
128
129
entity . gameObject . SetActive ( false ) ;
129
130
}
130
131
131
- private Poolable TakeEntity ( )
132
+ private Poolable GetEntityFromPool ( )
132
133
{
133
134
Poolable entity ;
134
135
135
136
if ( _currentCount == 0 )
136
137
{
137
138
entity = Object . Instantiate ( _prefab ) ;
138
139
entity . SetPool ( this ) ;
140
+ entity . gameObject . SetActive ( true ) ;
139
141
140
142
return entity ;
141
143
}
0 commit comments