Skip to content

Commit 18a9012

Browse files
committed
Update
1 parent 3115f31 commit 18a9012

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

Pool.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,47 @@ namespace ToolBox.Pools
88
[System.Serializable]
99
public class Pool
1010
{
11-
[SerializeField, AssetsOnly, ValueDropdown(nameof(GetPoolables))] private Poolable prefab = null;
12-
[SerializeField] private int startCount = 0;
13-
[SerializeField, SceneObjectsOnly] private Transform holder = null;
14-
[SerializeField] private GameObjectReactor objectInitializator = null;
11+
[SerializeField, AssetsOnly, ValueDropdown(nameof(GetPoolables))] private Poolable _prefab = null;
12+
[SerializeField] private int _startCount = 0;
13+
[SerializeField, SceneObjectsOnly] private Transform _holder = null;
14+
[SerializeField] private GameObjectReactor _objectInitializator = null;
1515

16-
private int currentCount = 0;
17-
private Queue<Poolable> entities = null;
16+
private int _currentCount = 0;
17+
private Queue<Poolable> _entities = null;
1818

1919
public Pool(Poolable prefab, int startCount, Transform holder, GameObjectReactor objectInitializator)
2020
{
21-
this.prefab = prefab;
22-
this.startCount = startCount;
23-
this.holder = holder;
24-
this.objectInitializator = objectInitializator;
21+
_prefab = prefab;
22+
_startCount = startCount;
23+
_holder = holder;
24+
_objectInitializator = objectInitializator;
2525
}
2626

2727
private IEnumerable<Poolable> GetPoolables() =>
2828
Resources.FindObjectsOfTypeAll<Poolable>();
2929

3030
public void Fill()
3131
{
32-
entities = new Queue<Poolable>(startCount);
33-
currentCount = startCount;
32+
_entities = new Queue<Poolable>(_startCount);
33+
_currentCount = _startCount;
3434

35-
Poolable original = Object.Instantiate(prefab, holder);
35+
Poolable original = Object.Instantiate(_prefab, _holder);
3636

37-
if (objectInitializator != null)
38-
objectInitializator.SendReaction(original.gameObject);
37+
if (_objectInitializator != null)
38+
_objectInitializator.SendReaction(original.gameObject);
3939

4040
AddToPool(original);
4141

42-
for (int i = 0; i < startCount - 1; i++)
42+
for (int i = 0; i < _startCount - 1; i++)
4343
{
44-
Poolable entity = Object.Instantiate(original, holder);
44+
Poolable entity = Object.Instantiate(original, _holder);
4545
AddToPool(entity);
4646
}
4747

4848
void AddToPool(Poolable newEntity)
4949
{
5050
newEntity.SetPool(this);
51-
entities.Enqueue(newEntity);
51+
_entities.Enqueue(newEntity);
5252
newEntity.gameObject.SetActive(false);
5353
}
5454
}
@@ -110,36 +110,36 @@ public void ReturnEntity(Poolable entity)
110110
if (entity.Pool != this)
111111
return;
112112

113-
entities.Enqueue(entity);
114-
currentCount++;
113+
_entities.Enqueue(entity);
114+
_currentCount++;
115115

116-
entity.transform.SetParent(holder, false);
116+
entity.transform.SetParent(_holder, false);
117117
entity.gameObject.SetActive(false);
118118
}
119119

120120
private Poolable TakeEntity()
121121
{
122122
Poolable entity;
123123

124-
if (currentCount == 0)
124+
if (_currentCount == 0)
125125
{
126-
entity = Object.Instantiate(prefab, holder);
126+
entity = Object.Instantiate(_prefab, _holder);
127127
entity.SetPool(this);
128128

129129
return entity;
130130
}
131131

132-
entity = entities.Dequeue();
132+
entity = _entities.Dequeue();
133133

134134
if (entity == null)
135135
{
136-
entity = Object.Instantiate(prefab, holder);
136+
entity = Object.Instantiate(_prefab, _holder);
137137
entity.SetPool(this);
138-
currentCount++;
138+
_currentCount++;
139139
}
140140

141141
entity.gameObject.SetActive(true);
142-
currentCount--;
142+
_currentCount--;
143143

144144
return entity;
145145
}

Poolable.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,39 @@ namespace ToolBox.Pools
66
[DisallowMultipleComponent]
77
public class Poolable : MonoBehaviour, IReactor
88
{
9-
[SerializeField] private Component component = null;
10-
[SerializeField] private Reactor onBackToPool = default;
11-
[SerializeField] private Reactor onBackFromPool = default;
9+
[SerializeField] private Component _component = null;
10+
[SerializeField] private Reactor _onBackToPool = null;
11+
[SerializeField] private Reactor _onBackFromPool = null;
1212

1313
public Pool Pool { get; private set; } = null;
14-
public Component Component => component;
14+
public Component Component => _component;
1515

16-
private bool isPooled = false;
17-
private bool isEnabled = true;
16+
private bool _isPooled = false;
17+
private bool _isEnabled = true;
1818

1919
public void ReturnToPool()
2020
{
21-
if (!isEnabled)
21+
if (!_isEnabled)
2222
return;
2323

24-
onBackToPool.SendReaction();
24+
_onBackToPool.SendReaction();
2525

2626
Pool.ReturnEntity(this);
27-
isEnabled = false;
27+
_isEnabled = false;
2828
}
2929

3030
public void ReturnFromPool()
3131
{
32-
onBackFromPool.SendReaction();
33-
isEnabled = true;
32+
_onBackFromPool.SendReaction();
33+
_isEnabled = true;
3434
}
3535

3636
public void SetPool(Pool pool)
3737
{
38-
if (!isPooled)
38+
if (!_isPooled)
3939
{
4040
Pool = pool;
41-
isPooled = true;
41+
_isPooled = true;
4242
}
4343
}
4444

0 commit comments

Comments
 (0)