Skip to content

Commit bb3d657

Browse files
committed
string Address Support
1 parent c7490bd commit bb3d657

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ public class GlobalAssetRefGameObjectPool : IPool, IShareable
1515
private readonly Dictionary<int, AssetRefGameObjectItemPool> _dicTrackingInstancePools = new();
1616

1717
private readonly Dictionary<AssetReferenceGameObject, AssetRefGameObjectPrefab> _poolKeyCache = new();
18+
private readonly Dictionary<string, AssetRefGameObjectPrefab> _poolStringKeyCache = new();
19+
20+
public async UniTask<GameObject> Rent(string address)
21+
{
22+
if (_poolStringKeyCache.TryGetValue(address, out var key))
23+
return await Rent(key);
24+
var assetRef = new AssetReferenceGameObject(address);
25+
this._poolStringKeyCache.Add(address, key = new AssetRefGameObjectPrefab { Source = assetRef, });
26+
return await Rent(key);
27+
}
1828

1929
public async UniTask<GameObject> Rent(AssetReferenceGameObject gameObjectReference)
2030
{
@@ -68,6 +78,7 @@ public void Dispose()
6878
_pools.Clear();
6979
_dicTrackingInstancePools.Clear();
7080
_poolKeyCache.Clear();
81+
_poolStringKeyCache.Clear();
7182
}
7283

7384
private class AssetRefGameObjectPrefabEqualityComparer : IEqualityComparer<AssetRefGameObjectPrefab>

0 commit comments

Comments
 (0)