npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

com.pika.objectpooling

v0.1.3

Published

Object Pooling is a great way to optimize your projects and lower the burden that is placed on the CPU when having to rapidly create and destroy GameObjects.

Downloads

1

Readme

Object Pooling SDK

Object Pooling is a great way to optimize your projects and lower the burden that is placed on the CPU when having to rapidly create and destroy GameObjects.

  • Generic type objects
  • Particle System

Table of Contents

Requirements

  • Unity 2019.4 or newer

Installation

There is only one method of installation available for the Object Pooling SDK:

  1. From within the Unity Editor navigate to Edit > Project Settings and then to the Package Manager settings tab.

    unity registry manager

  2. Create a New Scoped Registry by entering

    Name        npmjs
    URL         https://registry.npmjs.org
    Scope(s)    com.pika

    and click Save.

  3. Open the Window > Package Manager and switch to My Registries via the Packages: dropdown menu. You will see the Object Pooling SDK package available on which you can then click Install for the platforms you would like to include. Dependencies will be added automatically.

    Depending on your project configuration and if you are upgrading from a previous version, some of these steps may already be marked as "completed"

    my registries menu selection

Usage

Creating Instance

There is two method of creating a pool:

  1. Creating directly from the ObjectPooling class:
//Create a pool from ObjectPooling.Instance with desired prefab to be pooled as parameter
var exampleObjectPool = ObjectPooling.Instance.CreatePool(exampleObjectPrefab);

//You can expand pool options with these methods
exampleObjectPool.AsParent(transform); // Default transfrom of inactive items in the pool
exampleObjectPool.WithInitialSize(10); // Initial size o the pool
  1. Creating the instance
//Create a pool directly
var pool = new Pool<ExampleObject>(exampleObjectPrefab);
exampleObjectPool = ObjectPooling.Instance.InitializePool<Pool<ExampleObject>>(pool);

Spawn Objects

// Spawn object from the pool
var clone = exampleObjectPool.Spawn();

//If you trying to access the pool from other scopes, and you have the reference of the prefab
//You can access to that pool by calling this method
var exampleObjectPool = ObjectPooling.Instance.GetPool(prefab);
//Then spawn from that pool
var clone = exampleObjectPool.Spawn();

// You can pass parameters to the Spawn method like as Unity.Object.Instantiate(...) method
// Transform as parent
// Vector3 as global position
// Quaternion as global rotation
var clone = exampleObjectPool.Spawn(parent, position, rotation);

// If you have the reference of the prefab, you can just call:
prefab.Spawn(); // This method automaticly creates the pool by itself with default options

Recycle Objects

// Once you want to return the object to the pool, you need to call recycle method from the pool
exampleObject.Recycle(clone);

// If you have not reference of the pool you can just call these
// **Reminder: Calling Recycle() directly from the related pool as mentioned above is recommended in concern of performance!***
ObjectPooling.Instance.Recycle(clone);
// Or
clone.Recycle();

//All clones can be returned to the pool by this method
exampleObjectPool.RecycleAll();

//All clones can be destroyed including actives and inactives by this method
exampleObjectPool.DestroyAll();

Particle Pooling

To use particles with this system, you need to do two steps in target prefab:

  1. Set "Stop Action" to "CallBack" in particle system
  2. Add Component PooledParticleObject

my registries menu selection

Callbacks

  1. ICreationCallbackReceiver
  2. ISpawnCallbackReceiver
  3. IRecycleCallbackReceiver

These interfaces help you to receive callbacks when object is created, spawned and recycled

    public class ExampleObject : MonoBehaviour, ICreationCallbackReceiver, ISpawnCallbackReceiver, IRecycleCallbackReceiver
    {
        public void OnCreated()
        {
        }
        
        public void OnSpawned()
        {
        }
        
        public void OnRecycle()
        {
        }
    }

License

Modified MIT License