Skip to content

Commit ef5aa10

Browse files
committed
Clean
1 parent 7ede4ab commit ef5aa10

File tree

6 files changed

+13
-23
lines changed

6 files changed

+13
-23
lines changed
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using System;
2-
using UnityEngine;
1+
using UnityEngine;
32
using ZBase.Foundation.Pooling.AddressableAssets;
43

54
namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool
65
{
76
public class AssetRefGameObjectItemPool : AssetRefGameObjectPool
87
{
9-
internal event Action<GameObject> OnReturn;
10-
118
public AssetRefGameObjectItemPool(AssetRefGameObjectPrefab prefab) : base(prefab)
129
{
1310
}
@@ -19,11 +16,5 @@ protected override void ProcessNewInstance(GameObject instance)
1916
poolItem = instance.AddComponent<AssetRefGameObjectPoolItem>();
2017
poolItem.SetUp(this);
2118
}
22-
23-
protected override void ReturnPreprocess(GameObject instance)
24-
{
25-
base.ReturnPreprocess(instance);
26-
OnReturn?.Invoke(instance);
27-
}
2819
}
2920
}

Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/Foundation/Pools/GameObjectItemPool.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ namespace ZBase.Foundation.Pooling.GameObjectItem.LazyPool
77
{
88
public sealed class GameObjectItemPool : GameObjectPool
99
{
10-
internal event Action<GameObject> OnReturn;
1110
internal event Action<GameObjectItemPool> OnPoolEmpty;
1211
private readonly List<int > _poolItems = new();
1312

@@ -31,11 +30,5 @@ private void OnItemDestroy(GameObject instance)
3130
if(this._poolItems.Count == 0)
3231
OnPoolEmpty?.Invoke(this);
3332
}
34-
35-
protected override void ReturnPreprocess(GameObject instance)
36-
{
37-
base.ReturnPreprocess(instance);
38-
OnReturn?.Invoke(instance);
39-
}
4033
}
4134
}

Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalAssetRefGameObjectPool.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public async UniTask<GameObject> Rent(AssetRefGameObjectPrefab gameObjectReferen
3939
if (!_pools.TryGetValue(gameObjectReference, out var pool))
4040
{
4141
pool = new AssetRefGameObjectItemPool(gameObjectReference);
42-
pool.OnReturn += OnReturnToPool;
42+
pool.OnItemDestroyAction += RemoveTrackingItem;
43+
pool.OnReturnAction += RemoveTrackingItem;
4344
this._pools.Add(gameObjectReference, pool);
4445
}
4546
GameObject item = await pool.Rent();
@@ -69,7 +70,7 @@ public void ReleaseInstances(int keep, System.Action<GameObject> onReleased = nu
6970
pool.ReleaseInstances(keep, onReleased);
7071
}
7172

72-
private void OnReturnToPool(GameObject gameObject) => _dicTrackingInstancePools.Remove(gameObject.GetInstanceID());
73+
private void RemoveTrackingItem(GameObject gameObject) => _dicTrackingInstancePools.Remove(gameObject.GetInstanceID());
7374

7475
public void Dispose()
7576
{

Packages/ZBase.Foundation.Pooling/GameObjectLazyPool/GlobalPools/GlobalGameObjectPool.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public async UniTask<GameObject> Rent(GameObjectPrefab gameObjectReference)
2828
if (gameObjectReference.Source.scene.IsValid())
2929
throw new Exception($"Non Prefab not supported {gameObjectReference.Source.name}");
3030
pool = new GameObjectItemPool(gameObjectReference);
31-
pool.OnReturn += OnReturnToPool;
31+
pool.OnReturnAction += RemoveTrackingItem;
32+
pool.OnItemDestroyAction += RemoveTrackingItem;
3233
pool.OnPoolEmpty += OnPoolEmpty;
3334
this._pools.Add(instanceID, pool);
3435
}
@@ -92,7 +93,7 @@ private void RemoveCacheKey(int poolID)
9293
}
9394
}
9495

95-
private void OnReturnToPool(GameObject gameObject) =>
96+
private void RemoveTrackingItem(GameObject gameObject) =>
9697
this._dicTrackingInstancePools.Remove(gameObject.GetInstanceID());
9798

9899
public void Dispose()

Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/GameObjectPool{TPrefab}.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace ZBase.Foundation.Pooling.UnityPools
88
public class GameObjectPool<TPrefab> : UnityPool<GameObject, TPrefab> where TPrefab : IPrefab<GameObject>
99
{
1010
[SerializeField] private bool _dontApplyPrefabParentOnReturn;
11+
public event Action<GameObject> OnReturnAction;
1112

1213
public GameObjectPool()
1314
{
@@ -34,6 +35,7 @@ protected override void ReturnPreprocess(GameObject instance)
3435
instance.SetActive(false);
3536
if (_dontApplyPrefabParentOnReturn == false && Prefab != null)
3637
instance.transform.SetParent(Prefab.Parent);
38+
OnReturnAction?.Invoke(instance);
3739
}
3840
}
3941
}

Packages/ZBase.Foundation.Pooling/ZBase.Foundation.Pooling/UnityPools/Pools/UnityPool{T,TPrefab}.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace ZBase.Foundation.Pooling.UnityPools
1010
public class UnityPool<T, TPrefab>
1111
: IUnityPool<T, TPrefab>, IShareable, IDisposable where T : UnityEngine.Object where TPrefab : IPrefab<T>
1212
{
13+
public event Action<T> OnItemDestroyAction;
14+
1315
private readonly UniqueQueue<int, T> _queue;
1416

1517
[SerializeField] private TPrefab _prefab;
@@ -90,13 +92,13 @@ public void Return(T instance)
9092
_queue.TryEnqueue(instance.GetInstanceID(), instance);
9193
}
9294

93-
public void OnPoolItemDestroy(T instance)
95+
public virtual void OnPoolItemDestroy(T instance)
9496
{
9597
if (!instance)
9698
return;
97-
ReturnPreprocess(instance);
9899
_queue.Remove(instance.GetInstanceID());
99100
_prefab.Release(instance);
101+
OnItemDestroyAction?.Invoke(instance);
100102
}
101103

102104
[MethodImpl(MethodImplOptions.AggressiveInlining)]

0 commit comments

Comments
 (0)