### Unity C# Quick Start for PoolManager Source: https://github.com/batuhankanbur/poolmanager/blob/main/README.md Demonstrates how to set up and use the PoolManager for asynchronous object retrieval and release in Unity. It shows pre-creating a pool, asynchronously getting an object with transform modifications, and releasing it back to the pool. ```csharp // Prepare your AssetReference [SerializeField] private AssetReference myPrefab; // You can create a pool in advance if you want, but it's not mandatory! await PoolManager.CreatePool(myPrefab, initialSize: 10); // You can pull the object asynchronously and do transform interactions with chain methods. var go = await PoolManager.GetObjectAsync(myPrefab) .SetPosition(targetPosition) .SetParent(targetParent); //Or you can synchronously pull the object directly from the pool (not recommended). var go = PoolManager.GetObjectSync(myPrefab) .SetPosition(targetPosition) .SetParent(targetParent); // Release the object when done PoolManager.ReleaseObject(myPrefab, go); ``` -------------------------------- ### Unity C# PoolManager Async Extension Helpers Source: https://github.com/batuhankanbur/poolmanager/blob/main/README.md Illustrates the use of asynchronous extension methods provided by PoolManager to chain object setup operations. This allows for fluent configuration of position, rotation, and parent transformations immediately after retrieving an object asynchronously. ```csharp await PoolManager.GetObjectAsync(reference) .SetPosition(pos) .SetRotation(rot) .SetParent(parent); ``` -------------------------------- ### SetActiveState - C# Source: https://context7.com/batuhankanbur/poolmanager/llms.txt Demonstrates setting the active state of a pooled GameObject. This is useful for deferred activation scenarios where you want to perform additional setup before making the object visible. The example uses UniTask for asynchronous operations. ```csharp using PoolManager.Runtime; using UnityEngine; using UnityEngine.AddressableAssets; using Cysharp.Threading.Tasks; public class ActiveStateExample : MonoBehaviour { [SerializeField] private AssetReference prefab; public async UniTask SpawnInactiveAsync() { // Spawn inactive for deferred setup GameObject obj = await PoolManager.GetObjectAsync(prefab) .SetActiveState(false); // Perform additional setup... var component = obj.GetComponent(); component.Initialize(); // Then activate obj.SetActiveState(true); return obj; } } ``` -------------------------------- ### Complete Spawning System - C# Source: https://context7.com/batuhankanbur/poolmanager/llms.txt Shows a complete spawning system using PoolManager, including pre-warming pools, spawning enemies and projectiles, and automatic return-to-pool functionality. The system uses Addressables for asset loading and UniTask for asynchronous operations. Objects automatically return to the pool when disabled. ```csharp using PoolManager.Runtime; using UnityEngine; using UnityEngine.AddressableAssets; using Cysharp.Threading.Tasks; using System.Threading; public class EnemySpawnSystem : MonoBehaviour { [SerializeField] private AssetReference enemyPrefab; [SerializeField] private AssetReference projectilePrefab; [SerializeField] private Transform[] spawnPoints; [SerializeField] private Transform projectileContainer; private CancellationTokenSource cts; private async void Start() { cts = new CancellationTokenSource(); // Pre-warm pools during loading await UniTask.WhenAll( PoolManager.CreatePoolAsync(enemyPrefab, 10), PoolManager.CreatePoolAsync(projectilePrefab, 50) ); // Start spawn loop SpawnLoopAsync(cts.Token).Forget(); } private async UniTaskVoid SpawnLoopAsync(CancellationToken token) { while (!token.IsCancellationRequested) { await UniTask.Delay(2000, cancellationToken: token); var spawnPoint = spawnPoints[Random.Range(0, spawnPoints.Length)]; // Spawn enemy with fluent configuration GameObject enemy = await PoolManager.GetObjectAsync(enemyPrefab) .SetPosition(spawnPoint.position) .SetRotation(spawnPoint.rotation) .SetScale(Vector3.one); Debug.Log($"Spawned enemy at {spawnPoint.position}"); } } public async UniTask FireProjectileAsync(Vector3 position, Quaternion rotation) { // Spawn projectile with full transform setup await PoolManager.GetObjectAsync(projectilePrefab) .SetParent(projectileContainer) .SetPosition(position) .SetRotation(rotation) .SetScale(Vector3.one * 0.5f); } private void OnDestroy() { cts?.Cancel(); cts?.Dispose(); } } // Objects return to pool automatically when disabled // The PoolableObject component handles this via OnDisable public class Projectile : MonoBehaviour { [SerializeField] private float lifetime = 3f; private async void OnEnable() { await UniTask.Delay((int)(lifetime * 1000)); // Disabling returns object to pool automatically gameObject.SetActive(false); } } ``` -------------------------------- ### CreatePoolSync - Pre-warm Object Pool (Sync) Source: https://context7.com/batuhankanbur/poolmanager/llms.txt Synchronously creates and pre-instantiates objects into the pool. This method is useful for editor scripts or controlled initialization where blocking the main thread is acceptable. It takes an AssetReference or a string key representing the prefab and the initial number of objects to pre-warm. ```csharp using PoolManager.Runtime; using UnityEngine; using UnityEngine.AddressableAssets; public class SyncPoolInitializer : MonoBehaviour { [SerializeField] private AssetReference prefabRef; // WARNING: Blocks main thread during instantiation private void Awake() { // Synchronous pool creation PoolManager.CreatePoolSync(prefabRef, 10); // Or with string key PoolManager.CreatePoolSync("Prefabs/Projectile", 25); } } ``` -------------------------------- ### Async Extension Helpers Source: https://github.com/batuhankanbur/poolmanager/blob/main/README.md Chainable extension methods for asynchronously configuring retrieved GameObjects. ```APIDOC ## Async Extension Helpers ### Description These extension methods allow for chaining asynchronous configuration operations on GameObjects retrieved via `GetObjectAsync`. ### Usage Example ```csharp var go = await PoolManager.GetObjectAsync(reference) .SetPosition(pos) .SetRotation(rot) .SetParent(parent); ``` ### Available Extensions - **`SetPosition(Vector3 position)`**: Sets the position of the GameObject. - **`SetRotation(Quaternion rotation)`**: Sets the rotation of the GameObject. - **`SetParent(Transform parent)`**: Sets the parent of the GameObject. - **`SetPositionAndRotation(Vector3 pos, Quaternion rot)`**: Sets both position and rotation. - **`SetPositionAndRotation(Transform transform)`**: Sets position and rotation based on another transform. These extensions work on both `GameObject` and `UniTask` return types. ``` -------------------------------- ### CreatePoolAsync - Pre-warm Unity Object Pool with Addressables Source: https://context7.com/batuhankanbur/poolmanager/llms.txt Pre-instantiates a specified number of objects into the pool for later use. This warmup strategy prevents runtime hitches by loading objects during loading screens or initialization phases. It supports both AssetReference and string keys for Addressables. ```csharp using PoolManager.Runtime; using UnityEngine; using UnityEngine.AddressableAssets; using Cysharp.Threading.Tasks; public class PoolInitializer : MonoBehaviour { [SerializeField] private AssetReference bulletPrefab; [SerializeField] private AssetReference enemyPrefab; private async void Start() { // Pre-warm pools with AssetReference await PoolManager.CreatePoolAsync(bulletPrefab, 50); await PoolManager.CreatePoolAsync(enemyPrefab, 20); // Or use string keys for Addressables await PoolManager.CreatePoolAsync("Prefabs/Explosion", 30); Debug.Log("Pools ready!"); } } ``` -------------------------------- ### Utility Extensions Source: https://github.com/batuhankanbur/poolmanager/blob/main/README.md Standalone utility extension methods for configuring GameObjects. ```APIDOC ## Utility Extensions ### Description These are utility extension methods that can be applied to GameObjects, often used in conjunction with pooled objects. ### Available Extensions - **`SetPosition(Vector3 position)`**: Sets the position of the GameObject. - **`SetRotation(Quaternion rotation)`**: Sets the rotation of the GameObject. - **`SetParent(Transform parent)`**: Sets the parent of the GameObject. - **`SetPositionAndRotation(Vector3 pos, Quaternion rot)`**: Sets both position and rotation. - **`SetPositionAndRotation(Transform transform)`**: Sets position and rotation based on another transform. These extensions work on both `GameObject` and `UniTask` return types. ``` -------------------------------- ### Pool Management API Source: https://github.com/batuhankanbur/poolmanager/blob/main/README.md Core methods for managing object pools, including creation, retrieval, and release of pooled objects. ```APIDOC ## Pooling API ### Description Provides methods to manage object pools, allowing for preloading, asynchronous or synchronous retrieval, and returning objects to the pool. ### Methods #### `CreatePool` - **Description:** Preloads a specified number of objects into the pool for a given asset reference. - **Parameters:** - `reference` (AssetReference) - Required - The asset reference to create a pool for. - `initialSize` (int) - Optional - The initial number of objects to preload into the pool. Defaults to 0. - **Usage:** `await PoolManager.CreatePool(myPrefab, initialSize: 10);` #### `GetObjectAsync` - **Description:** Asynchronously retrieves an object from the pool. This is the recommended method for retrieving objects as it's non-blocking. - **Parameters:** - `reference` (AssetReference) - Required - The asset reference to retrieve an object from. - **Returns:** `UniTask` - A task that resolves to the retrieved GameObject. - **Usage:** `var go = await PoolManager.GetObjectAsync(myPrefab);` #### `GetObjectSync` - **Description:** Synchronously retrieves an object from the pool. **Warning:** This method is blocking and may freeze the main thread. Use only when absolutely necessary. - **Parameters:** - `reference` (AssetReference) - Required - The asset reference to retrieve an object from. - **Returns:** `GameObject` - The retrieved GameObject. - **Usage:** `var go = PoolManager.GetObjectSync(myPrefab);` #### `ReleaseObject` - **Description:** Returns a previously retrieved object back to its corresponding pool. - **Parameters:** - `reference` (AssetReference) - Required - The asset reference the object belongs to. - `obj` (GameObject) - Required - The GameObject to release back into the pool. - **Usage:** `PoolManager.ReleaseObject(myPrefab, go);` ``` -------------------------------- ### GetObjectAsync - Retrieve Object from Pool (Async) in Unity Source: https://context7.com/batuhankanbur/poolmanager/llms.txt Asynchronously retrieves an object from the pool, instantiating a new one if the pool is empty. This is the recommended method for runtime object spawning as it doesn't block the main thread. It supports fluent API for transform manipulation and Addressables string keys. ```csharp using PoolManager.Runtime; using UnityEngine; using UnityEngine.AddressableAssets; using Cysharp.Threading.Tasks; public class BulletSpawner : MonoBehaviour { [SerializeField] private AssetReference bulletPrefab; [SerializeField] private Transform firePoint; public async UniTask SpawnBulletAsync() { // Basic async retrieval GameObject bullet = await PoolManager.GetObjectAsync(bulletPrefab); bullet.transform.position = firePoint.position; bullet.transform.rotation = firePoint.rotation; return bullet; } public async UniTask SpawnWithChainMethodsAsync() { // Fluent API with chained transform setup GameObject bullet = await PoolManager.GetObjectAsync(bulletPrefab) .SetPosition(firePoint.position) .SetRotation(firePoint.rotation) .SetParent(null) .SetScale(Vector3.one); return bullet; } public async UniTask SpawnUsingStringKeyAsync() { // Using Addressables string key instead of AssetReference GameObject explosion = await PoolManager.GetObjectAsync("Prefabs/Explosion") .SetPosition(transform.position); } } ``` -------------------------------- ### SetScale - Set Local Scale of Pooled GameObject Source: https://context7.com/batuhankanbur/poolmanager/llms.txt Sets the local scale of a pooled GameObject. This extension method allows you to resize the object relative to its parent's scale. It accepts a `Vector3` representing the desired local scale. ```csharp using PoolManager.Runtime; using UnityEngine; using UnityEngine.AddressableAssets; using Cysharp.Threading.Tasks; public class ScaleExample : MonoBehaviour { [SerializeField] private AssetReference prefab; public async UniTask SpawnScaledAsync() { await PoolManager.GetObjectAsync(prefab) .SetPosition(Vector3.zero) .SetScale(new Vector3(2f, 2f, 2f)); } } ``` -------------------------------- ### GetObjectSync - Retrieve Object from Pool (Sync) in Unity Source: https://context7.com/batuhankanbur/poolmanager/llms.txt Synchronously retrieves an object from the pool. This method blocks the main thread and should only be used in controlled scenarios like editor scripts or startup initialization where async is not practical. It supports Addressables string keys and fluent API for transform manipulation. ```csharp using PoolManager.Runtime; using UnityEngine; using UnityEngine.AddressableAssets; public class SyncSpawner : MonoBehaviour { [SerializeField] private AssetReference prefabRef; // WARNING: This blocks the main thread - use sparingly! public GameObject SpawnImmediate() { // Synchronous retrieval (may cause frame hitches) GameObject obj = PoolManager.GetObjectSync(prefabRef) .SetPosition(Vector3.zero) .SetRotation(Quaternion.identity); return obj; } public GameObject SpawnWithStringKey() { // Using string key synchronously return PoolManager.GetObjectSync("Prefabs/Enemy") .SetPosition(transform.position); } } ``` -------------------------------- ### SetPosition - Set World Position of Pooled GameObject Source: https://context7.com/batuhankanbur/poolmanager/llms.txt Sets the world position of a pooled GameObject. This extension method can be chained directly on the result of an asynchronous object retrieval (e.g., `GetObjectAsync`) or applied to a retrieved `GameObject`. It takes a `Vector3` representing the desired world position. ```csharp using PoolManager.Runtime; using UnityEngine; using UnityEngine.AddressableAssets; using Cysharp.Threading.Tasks; public class PositionExample : MonoBehaviour { [SerializeField] private AssetReference prefab; public async UniTask SpawnAtPositionAsync() { // Chain directly on async call await PoolManager.GetObjectAsync(prefab) .SetPosition(new Vector3(10f, 0f, 5f)); // Or on GameObject directly GameObject obj = await PoolManager.GetObjectAsync(prefab); obj.SetPosition(Vector3.up * 2f); } } ``` -------------------------------- ### SetRotation - Set World Rotation of Pooled GameObject Source: https://context7.com/batuhankanbur/poolmanager/llms.txt Sets the world rotation of a pooled GameObject using a `Quaternion`. This method allows you to orient the object in world space. It can be chained with other extension methods for fluent manipulation. ```csharp using PoolManager.Runtime; using UnityEngine; using UnityEngine.AddressableAssets; using Cysharp.Threading.Tasks; public class RotationExample : MonoBehaviour { [SerializeField] private AssetReference prefab; public async UniTask SpawnWithRotationAsync() { await PoolManager.GetObjectAsync(prefab) .SetPosition(transform.position) .SetRotation(Quaternion.Euler(0f, 90f, 0f)); } } ``` -------------------------------- ### SetLocalPosition - Set Local Position of Pooled GameObject Source: https://context7.com/batuhankanbur/poolmanager/llms.txt Sets the local position of a pooled GameObject relative to its parent transform. This is useful when you want to position an object within its parent's coordinate space. It accepts a `Vector3` for the local offset. ```csharp using PoolManager.Runtime; using UnityEngine; using UnityEngine.AddressableAssets; using Cysharp.Threading.Tasks; public class LocalPositionExample : MonoBehaviour { [SerializeField] private AssetReference prefab; [SerializeField] private Transform container; public async UniTask SpawnWithLocalOffsetAsync() { await PoolManager.GetObjectAsync(prefab) .SetParent(container) .SetLocalPosition(new Vector3(0f, 1f, 0f)); } } ``` -------------------------------- ### SetParent - Set Parent Transform of Pooled GameObject Source: https://context7.com/batuhankanbur/poolmanager/llms.txt Sets the parent transform of a pooled GameObject. This method allows you to re-parent the object to a new transform. It includes an optional `worldPositionStays` parameter to control whether the object's world position is maintained after parenting. ```csharp using PoolManager.Runtime; using UnityEngine; using UnityEngine.AddressableAssets; using Cysharp.Threading.Tasks; public class ParentExample : MonoBehaviour { [SerializeField] private AssetReference prefab; [SerializeField] private Transform container; public async UniTask SpawnAsChildAsync() { // Set parent, maintaining local position await PoolManager.GetObjectAsync(prefab) .SetParent(container, worldPositionStays: false) .SetLocalPosition(Vector3.zero); // Set parent, maintaining world position await PoolManager.GetObjectAsync(prefab) .SetParent(container, worldPositionStays: true); } } ``` -------------------------------- ### SetLocalRotation - Set Local Rotation of Pooled GameObject Source: https://context7.com/batuhankanbur/poolmanager/llms.txt Sets the local rotation of a pooled GameObject relative to its parent. This method is used to control the object's orientation within its parent's coordinate system. It takes a `Quaternion` value. ```csharp using PoolManager.Runtime; using UnityEngine; using UnityEngine.AddressableAssets; using Cysharp.Threading.Tasks; public class LocalRotationExample : MonoBehaviour { [SerializeField] private AssetReference prefab; [SerializeField] private Transform parent; public async UniTask SpawnWithLocalRotationAsync() { await PoolManager.GetObjectAsync(prefab) .SetParent(parent) .SetLocalRotation(Quaternion.identity); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.