Unclaimed Package Is this your package? Claim it to unlock full analytics and manage your listing.
Claim This Package

Install via UPM

Add to Unity Package Manager using this URL

https://www.pkglnk.dev/vcontainer-pool.git?path=Assets/VContainerPool

README Markdown

Copy this to your project's README.md

Style
Preview
pkglnk installs badge
## Installation

Add **VContainer object pooling** to your Unity project via Package Manager:

1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/vcontainer-pool.git?path=Assets%2FVContainerPool
```

[![pkglnk](https://www.pkglnk.dev/badge/vcontainer-pool.svg?style=pkglnk)](https://www.pkglnk.dev/pkg/vcontainer-pool)

README

Description

A pool implementation that lets you easily register any Monobehavior as a Unity objectPool. The pool is customizable and has built-in functions such as defining a retrieve/release strategy, defining a prewarming budget, spawning under a specific transform

Installation

  1. Install with openupm openupm add com.basho-kit.vcontainer-pool. See
  2. Or add to your manifest.json the following
"com.valeriocorso.vcontainer-pool": "https://github.com/Valerio-Corso/VContainer-ViewPool.git?path=Assets/VContainerPool#main

Usage

Registration

using Vcontainer.ObjectPool;

...
[SerializeField] private StorageSlotView storageSlotView;

...
// Helper method that uses a default strategy, toggling the object active state and parenting to a give transform
builder.RegisterUISlotsPool(storageSlotView, 25);

// Helper method that uses a default strategy, keeping it always active and just moving it out of bounds
builder.RegisterWorldEntityPool(storageSlotView, 50);

// Or you could manually define yours
var poolName = "mypool";
var config = new ViewPoolConfig(
    initialSize: 10,
    viewPoolTransformName: poolName,
    releaseStrategy: DisableObject | ReparentToPool,
    retrieveeStrategy: PoolRetrieveStrategy.ActivateObject | PoolRetrieveStrategy.MoveToCoords,
    prewarmBudgetMs: 10f,
    outOfBoundsOffset: new Vector3(10f, 10f, 10f)
);

builder.RegisterViewPoolFactory(prefab, config, lifetime);

View

Your pool object must implement IViewPool, this gives you two methods you can implement, example:

public void OnReturn() {
    _sprite.sprite = null;
    _t = 0f;
    _onComplete = null;
    _collider.enabled = false;
    _audioSource.enabled = false;
    _moveSequence.Complete();
}

public void OnRetrieve() {
    _collider.enabled = true;
    _audioSource.enabled = true;
}

Comments

No comments yet. Be the first!