Skip to content

Commit b536db7

Browse files
committed
UnityEvents instead of Interfaces
1 parent d9c7dcc commit b536db7

File tree

6 files changed

+14
-61
lines changed

6 files changed

+14
-61
lines changed

IPoolInitializer.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

IPoolInitializer.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

IPoolResetter.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

IPoolResetter.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Pool.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ namespace ToolBox.Pools
77
[System.Serializable]
88
public class Pool
99
{
10-
[SerializeField, AssetsOnly] private Poolable prefab = null;
11-
[SerializeField] private int startCount = 0;
12-
[SerializeField] private bool isResizable = false;
13-
[SerializeField, SceneObjectsOnly] private Transform holder = null;
10+
[SerializeField, AssetsOnly, TabGroup("Data")] private Poolable prefab = null;
11+
[SerializeField, TabGroup("Data")] private int startCount = 0;
12+
[SerializeField, TabGroup("Data")] private bool isResizable = false;
13+
[SerializeField, SceneObjectsOnly, TabGroup("Data")] private Transform holder = null;
14+
15+
[SerializeField, ReadOnly, TabGroup("Debug")] private bool isFilled = false;
16+
[SerializeField, ReadOnly, TabGroup("Debug")] private int currentCount = 0;
1417

1518
private Queue<Poolable> entities = null;
16-
private bool isFilled = false;
17-
private int currentCount = 0;
1819

1920
public Pool(Poolable prefab, int startCount, bool isResizable, Transform holder)
2021
{
@@ -145,6 +146,7 @@ private Poolable TakeEntity()
145146
return entity;
146147
}
147148

148-
private bool IsEmpty(Poolable entity) => !isResizable && entity == null;
149+
private bool IsEmpty(Poolable entity) =>
150+
!isResizable && entity == null;
149151
}
150152
}

Poolable.cs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using UnityEngine;
2+
using UnityEngine.Events;
23

34
namespace ToolBox.Pools
45
{
@@ -7,40 +8,26 @@ public class Poolable : MonoBehaviour
78
{
89
public Pool Pool { get; private set; } = null;
910

10-
private IPoolResetter[] poolResetters = null;
11-
private IPoolInitializer[] poolInitializers = null;
12-
13-
private int poolResettersCount = 0;
14-
private int poolInitializersCount = 0;
11+
[SerializeField] private UnityEvent OnBackToPool = null;
12+
[SerializeField] private UnityEvent OnBackFromPool = null;
1513

1614
private bool isPooled = false;
1715
private bool isEnabled = true;
1816

19-
private void Awake()
20-
{
21-
poolResetters = GetComponentsInChildren<IPoolResetter>();
22-
poolInitializers = GetComponentsInChildren<IPoolInitializer>();
23-
poolResettersCount = poolResetters.Length;
24-
poolInitializersCount = poolInitializers.Length;
25-
}
26-
2717
public void ReturnToPool()
2818
{
2919
if (!isEnabled)
3020
return;
3121

32-
for (int i = 0; i < poolResettersCount; i++)
33-
poolResetters[i].Reset();
22+
OnBackToPool?.Invoke();
3423

3524
Pool.ReturnEntity(this);
3625
isEnabled = false;
3726
}
3827

3928
public void ReturnFromPool()
4029
{
41-
for (int i = 0; i < poolInitializersCount; i++)
42-
poolInitializers[i].Initialize();
43-
30+
OnBackFromPool?.Invoke();
4431
isEnabled = true;
4532
}
4633

0 commit comments

Comments
 (0)