Skip to content

Latest commit

 

History

History
92 lines (70 loc) · 3.4 KB

README.md

File metadata and controls

92 lines (70 loc) · 3.4 KB

FastPool

Library of scripts to help facilitate the creation of a pool of objects. Uses efficient data structures at its core.

Watch on GitHub Star on GitHub
<< Advantages | How to use | Install | Download >>

Advantages of the library

This library will help you quickly and efficiently develop object pools in your projects. The library is written very simply and intuitively (implements the classic design pattern - the object pool). In addition, this library uses an efficient data structure - FreeList.

After a series of tests of different data structures (Array, List, Queue, Stack, ConcurrentBag and FreeList), the most effective data structure at the core of this library was FreeList. The time required for basic operations is shown below.

0

Thus, FreeList is thousands of times more efficient than familiar data structures.


How to use this library?

  1. First, your pool object must realise the IPoolable interface.
using UnityEngine;
using FastPool;

public class SomePoolObject : MonoBehaviour, IPoolable
{
    public IPoolable NextInactiveObject { get; set; }

    public void ResetStateObject()
    {
        // some action for reset state of pool object
    }
}
  1. Secondly, you need to realise an object pool manager script (for example, EnemiesController, which will control the logic of enemies and have objects of enemies).
using UnityEngine;
using FastPool;

public class SomePoolManager : MonoBehaviour
{
    [SerializeField] private SomePoolObject poolObjectPrefab;
    [SerializeField] private int objectsCount;

    private PoolManager<SomePoolObject> poolManager;

    private void Start()
    {
        Initialize();
    }

    private void Initialize()
    {
        poolManager = new PoolManager<SomePoolObject>(objectsCount, ObjectGenerator);
    }

    private SomePoolObject ObjectGenerator()
    {
        return Instantiate(poolObjectPrefab);
    }

    public void PopObjectsTest()
    {
        poolManager.Pop();
    }

    public void PushObjectsTest(SomePoolObject unnecessaryPoolObject)
    {
        poolManager.Push(unnecessaryPoolObject);
    }
}
  1. Done! Now you can focus on other tasks in your project.

How to install?

  1. Download SimpleLocalization.unitypackage and using UnityPackageManager.
  2. The Unity Package Manager (UPM) is a new method to manage external packages. It keeps package contents separate from your main project files.

Modify your project's Packages/manifest.json file adding this line: "com.lodza.fastpool": "https://github.com/RodionLodza/FastPool.git#package-branch"

To access classes inside of this package you will need to add a reference to com.lodza.fastpool.asmdef to your project's assembly definition file.

License