Skip to content

Commit ebacbb5

Browse files
committed
Add preload Addressable
1 parent ca88eb0 commit ebacbb5

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Packages/ZBase.Foundation.Pooling/GameObjectLazyPool.Addressables/GlobalPools/Extensions/LazyAssetRefGameObjectPool.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ public static class LazyAssetRefGameObjectPool
1010
{
1111
private static GlobalAssetRefGameObjectPool GlobalGameObjectPool => SharedPool.Of<GlobalAssetRefGameObjectPool>();
1212

13+
#region Preload
14+
15+
public static async UniTask Preload(string address) =>
16+
GlobalGameObjectPool.Return(await GlobalGameObjectPool.Rent(address));
17+
18+
public static async UniTask Preload(AssetReferenceGameObject gameObjectReference) =>
19+
GlobalGameObjectPool.Return(await GlobalGameObjectPool.Rent(gameObjectReference));
20+
21+
public static async UniTask Preload(AssetRefGameObjectPrefab gameObjectReference) =>
22+
GlobalGameObjectPool.Return(await GlobalGameObjectPool.Rent(gameObjectReference));
23+
24+
#endregion
25+
1326
public static async UniTask<GameObject> Rent(string address)
1427
=> await GlobalGameObjectPool.Rent(address);
1528

@@ -18,6 +31,22 @@ public static async UniTask<GameObject> Rent(AssetReferenceGameObject gameObject
1831

1932
public static async UniTask<GameObject> Rent(AssetRefGameObjectPrefab gameObjectReference)
2033
=> await GlobalGameObjectPool.Rent(gameObjectReference);
34+
35+
public static async UniTask<GameObject> Rent(AssetRefGameObjectPrefab gameObjectReference, Vector3 pos, bool activeOnSpawn = true)
36+
{
37+
var go = await GlobalGameObjectPool.Rent(gameObjectReference);
38+
go.transform.position = pos;
39+
go.SetActive(activeOnSpawn);
40+
return go;
41+
}
42+
43+
public static async UniTask<GameObject> Rent(AssetRefGameObjectPrefab gameObjectReference, Vector3 pos, Quaternion rot, bool activeOnSpawn = true)
44+
{
45+
var go = await GlobalGameObjectPool.Rent(gameObjectReference);
46+
go.transform.SetPositionAndRotation(pos, rot);
47+
go.SetActive(activeOnSpawn);
48+
return go;
49+
}
2150

2251
public static void Return(GameObject gameObject)
2352
=> GlobalGameObjectPool.Return(gameObject);

Packages/ZBase.Foundation.Pooling/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.zbase.foundation.pooling",
33
"displayName": "ZBase.Foundation.Pooling",
4-
"version": "2.3.14",
4+
"version": "2.3.16",
55
"unity": "2021.3",
66
"documentationUrl": "https://github.com/WolffunGame/Unity.Pooling/blob/main/README.md",
77
"dependencies": {

0 commit comments

Comments
 (0)