com.amanotes.prefabpool 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/Docs/PrefabPool-API.md +13 -1
- package/README.md +2 -2
- package/Runtime/PrefabPool.cs +25 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.1.0] - 2026-10-06
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- `PrefabPool.ReleaseForSceneChange()` - lets a pool outlive the scene that used it: returns every checked-out instance to its pool and drops scene-bound spawn parents. Pooled instances stay alive; re-register the groups with the next scene's parents.
|
|
7
|
+
|
|
3
8
|
## [2.0.3] - 2026-09-24
|
|
4
9
|
|
|
5
10
|
### Added
|
package/Docs/PrefabPool-API.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# PrefabPool API Reference
|
|
2
2
|
|
|
3
|
-
**Package:** `com.amanotes.prefabpool` | **Version:** 2.0
|
|
3
|
+
**Package:** `com.amanotes.prefabpool` | **Version:** 2.1.0 | **Namespace:** `Amanotes.Core`
|
|
4
4
|
|
|
5
5
|
Generic object pooling system to eliminate garbage collection spikes from frequent instantiation/destruction.
|
|
6
6
|
|
|
@@ -370,3 +370,15 @@ var unknown = group.Get("unknown_id");
|
|
|
370
370
|
## See Also
|
|
371
371
|
|
|
372
372
|
- [PrefabPool README](../README.md)
|
|
373
|
+
|
|
374
|
+
---
|
|
375
|
+
|
|
376
|
+
## Outliving a scene
|
|
377
|
+
|
|
378
|
+
`PrefabPool.ReleaseForSceneChange()` lets a pool survive the scene that used it (for example a pool in `DontDestroyOnLoad`):
|
|
379
|
+
|
|
380
|
+
- every checked-out instance is returned to its pool;
|
|
381
|
+
- scene-bound spawn parents are dropped (`group.Register(pool, null)`);
|
|
382
|
+
- pooled instances stay alive.
|
|
383
|
+
|
|
384
|
+
Call `RegisterGroup(group, newSpawnParent)` again once the next scene's parent exists. No-op after `MarkShutdown()` / `DestroyPool()`.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# PrefabPool
|
|
2
2
|
|
|
3
3
|
**Package:** `com.amanotes.prefabpool`
|
|
4
|
-
**Version:** 2.0
|
|
4
|
+
**Version:** 2.1.0
|
|
5
5
|
|
|
6
6
|
Generic object pooling system for Unity with lifecycle callbacks and material pooling support.
|
|
7
7
|
|
|
@@ -30,7 +30,7 @@ Add the package to your Unity project via `Packages/manifest.json`:
|
|
|
30
30
|
```json
|
|
31
31
|
{
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"com.amanotes.prefabpool": "2.0
|
|
33
|
+
"com.amanotes.prefabpool": "2.1.0"
|
|
34
34
|
},
|
|
35
35
|
"scopedRegistries": [
|
|
36
36
|
{
|
package/Runtime/PrefabPool.cs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
using System;
|
|
2
2
|
using System.Collections;
|
|
3
3
|
using System.Collections.Generic;
|
|
4
|
+
#if UNITY_EDITOR
|
|
4
5
|
using UnityEditor;
|
|
6
|
+
#endif
|
|
5
7
|
using UnityEngine;
|
|
6
8
|
using UnityObject = UnityEngine.Object;
|
|
7
9
|
|
|
@@ -370,6 +372,29 @@ namespace Amanotes.Core
|
|
|
370
372
|
public bool IsReady => _isReady;
|
|
371
373
|
|
|
372
374
|
public void MarkShutdown() => _isDestroyed = true;
|
|
375
|
+
|
|
376
|
+
/// <summary>
|
|
377
|
+
/// Lets the pool outlive the scene that used it: returns every checked-out instance to its pool and drops
|
|
378
|
+
/// scene-bound spawn parents. Pooled instances stay alive; re-register the groups with the next scene's parents.
|
|
379
|
+
/// </summary>
|
|
380
|
+
public void ReleaseForSceneChange()
|
|
381
|
+
{
|
|
382
|
+
if (_isDestroyed) return;
|
|
383
|
+
|
|
384
|
+
var liveIds = new List<UnityObjectId>(_liveInstances.Keys);
|
|
385
|
+
for (var i = 0; i < liveIds.Count; i++)
|
|
386
|
+
{
|
|
387
|
+
var id = liveIds[i];
|
|
388
|
+
var go = _liveInstances[id];
|
|
389
|
+
if (go != null && _instanceTypeMap.TryGetValue(id, out var entry))
|
|
390
|
+
entry.Return(go, transform);
|
|
391
|
+
_instanceTypeMap.Remove(id);
|
|
392
|
+
_liveInstances.Remove(id);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
for (var i = 0; i < _groupOrder.Count; i++)
|
|
396
|
+
_groupOrder[i].Register(this, null);
|
|
397
|
+
}
|
|
373
398
|
|
|
374
399
|
public void RegisterGroup(PoolGroup group, Transform spawnParent)
|
|
375
400
|
{
|