Skip to content

Commit

Permalink
NightPool 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MeeXaSiK committed Sep 12, 2023
1 parent 1328bc0 commit 4ac3d28
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Code/Extensions.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Code/Extensions/NightPoolExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using UnityEngine;

namespace NTC.Pool
{
public static class NightPoolExtensions
{
/// <summary>
/// Despawns a particle system when it finishes playing.
/// </summary>
/// <param name="particleSystem">A particle system to despawn on complete.</param>
/// <returns>A particle system to despawn on complete.</returns>
public static ParticleSystem DespawnOnComplete(this ParticleSystem particleSystem)
{
NightPool.Despawn(particleSystem.gameObject, particleSystem.main.duration);
return particleSystem;
}
}
}
3 changes: 3 additions & 0 deletions Code/Extensions/NightPoolExtensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ NightPool.Despawn(newGameObject);
* [Callbacks Type](#callbacks-type)
* [Update Type](#update-type)
* [Reaction On Repeated Delayed Despawn](#reaction-on-repeated-delayed-despawn)
* [Extensions](#-extensions)
* [Particle System Auto Despawn](#particle-system-auto-despawn)
* [Preload In Editor](#-preload-in-editor)
* [How to attach DI container](#-how-to-attach-di-container)
* [How to reset pooled rigidbody](#-how-to-reset-pooled-rigidbody)
Expand Down Expand Up @@ -89,6 +91,8 @@ Find `NightPoolGlobal.cs` in the project files and drag it onto any game object.
## Basics
Use static class `NightPool` to `Spawn` or `Despawn` game objects instead of `Instantiate` and `Destroy`.
```csharp
using NTC.Pool;

public class Example : MonoBehaviour
{
[SerializeField] private GameObject _gameObjectPrefab;
Expand Down Expand Up @@ -596,6 +600,29 @@ Shows the current status of the clone.
| Despawned | Clone is despawned. |
| SpawnedOverCapacity | Clone is spawned over capacity of the attached pool and will be just destroyed by `Despawn`. |

# 🔸 Extensions
## Particle System Auto Despawn
You can despawn a particle system when it finishes playing using extension method `DespawnOnComplete` from the `NightPoolExtensions` class:
```csharp
using NTC.Pool;

public class Example : MonoBehaviour
{
[SerializeField] private ParticleSystem _particleSystemPrefab;

public void PlayParticle()
{
NightPool
.Spawn(_particleSystemPrefab)
.DespawnOnComplete();
}
}
```
Additionally, this extension method returns `ParticleSystem`:
```csharp
ParticleSystem spawnedParticleSystem = NightPool.Spawn(_particleSystemPrefab).DespawnOnComplete();
```

# 🔸 Preload In Editor
You can also preload game objects in the editor.

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"name": "Night Train Code",
"url": "https://www.youtube.com/@NightTrainCode/"
},
"displayName": "NightPool",
"description": "NightPool - fast object pool for Unity.",
"displayName": "Night Pool",
"description": "Night Pool is a fast game object pool for Unity.",
"unity": "2020.3",
"version": "3.0.0",
"version": "3.1.0",
"keywords": [
"nightpool",
"objectpool",
Expand Down

0 comments on commit 4ac3d28

Please sign in to comment.