Variables

Table of Content

Table of Content

Table of Content

PoolObject

Generic Pool system for unity Objects

PoolObject

You will be able to choose a prefab

A default parent

A maximum count of object possible

A prewarm count created on the Initialization

using MVsToolkit.Pool;



public PoolObject<GameObject> bullets;

private void Start()
{
    bullets.Init();
}

public void Attack()
{
    if (bullets.TryGet(out GameObject bullet))
    {
        bullet.transform.position = attackPoint.position;

        this.Delay(() =>
        {
            bullets.Release(bullet);
        }, 3);
    }
}


Methods :


void Init()

Initializes the pool.

Creates and deactivates instances if prewarming is enabled.

Call before use or it will be called automatically on first access.



bool TryGet(out T t, Transform parent = null)

Retrieves an instance from the pool and activates it.

Returns true if an instance is provided, otherwise false if the maximum size is reached.

param "t" Retrieved instance

param "parent" Optional parent for the retrieved instance, otherwise uses "PoolObject{T}.parent"



void Release(T c)

Returns an instance to the pool. The instance is deactivated and reassigned under "parent"

If the limit is reached, the instance is destroyed.



void Create()

Creates a new instance from the prefab referenced

Automatically called if the pool is empty.



void SetParent(Transform parent)

Sets the default parent used during pool operations.

param "parent" Parent transform to use


Require the namespace MVsTookit.Pool

Create a free website with Framer, the website builder loved by startups, designers and agencies.