Giter VIP home page Giter VIP logo

simple-pool's Introduction

#NVJOB Simple Pool 1.2.1

GitHub Logo

This is a simple pool for optimizing object loading.

Permanent creation and destruction of objects in your scene, very expensive in terms of memory management, use the Simple Pool object pool to save memory and improve performance.

All objects in the pool are loaded during initialization, and then retrieved from the pool and returned back to the pool without sacrificing performance.
The pool allows you to completely abandon Instantiate and Destroy after initialization.


Prerequisites

To work on the project, you will need a Unity version of at least 2019.1.8 (64-bit).

Information

Getting an object from a pool:

GameObject obj = SimplePool.GiveObj(0);

SimplePool.GiveObj() instead of using Instantiate(Object).
SimplePool.GiveObj(numElement)-> numElement - number of the Element in editor (SimplePool).

GitHub Logo

After all the transformations of the object, activate it:

obj.SetActive(true);

Return object to the pool, remove from the scene:

SimplePool.Takeobj(obj);

SimplePool.Takeobj() instead of using - Destroy(Object).
SimplePool.Takeobj(GameObject)-> GameObject - is an object that to be returned to the pool.

The number of elements in the editor (SimplePool):

SimplePool.numObjectsList

Checking that the pool is not empty:

GameObject obj = SimplePool.GiveObj(0);
if (obj != null)
{
}

If the pool is empty it will return null.

Example script:

using UnityEngine;

public class Example : MonoBehaviour
{
    GameObject obj;

    void Start()
    {
        if(SimplePool.numObjectsList == 0) obj = SimplePool.GiveObj(0);
        else obj = SimplePool.GiveObj(Random.Range(0, SimplePool.numObjectsList));
        if (obj != null)
        {
            obj.transform.SetPositionAndRotation(transform.position, transform.rotation);
            obj.transform.parent = transform;
            obj.SetActive(true);
            Invoke("DestroyObject", 5);
        }
    }

    void DestroyObject()
    {
        SimplePool.Takeobj(obj);
    }
}

Video manual:

https://www.youtube.com/watch?v=fhuhPnpSoJU


GitHub Logo


Authors: #NVJOB. Developer Nicholas Veselov. Разработчик Николай Веселов. Санкт-Петербург.

License: MIT License. Clarification of licenses.

🖤 Donate:
paypal.me/nvjob

simple-pool's People

Contributors

nvjob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.