com.amanotes.prefabpool 2.0.2 → 2.0.3
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 +1 -1
- package/README.md +2 -2
- package/Runtime/PrefabPool.cs +22 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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.0.3 | **Namespace:** `Amanotes.Core`
|
|
4
4
|
|
|
5
5
|
Generic object pooling system to eliminate garbage collection spikes from frequent instantiation/destruction.
|
|
6
6
|
|
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.0.3
|
|
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.0.3"
|
|
34
34
|
},
|
|
35
35
|
"scopedRegistries": [
|
|
36
36
|
{
|
package/Runtime/PrefabPool.cs
CHANGED
|
@@ -196,6 +196,12 @@ namespace Amanotes.Core
|
|
|
196
196
|
{
|
|
197
197
|
_prefabPool?.Return(this, gameObject);
|
|
198
198
|
}
|
|
199
|
+
|
|
200
|
+
public bool TryReturn(GameObject gameObject)
|
|
201
|
+
{
|
|
202
|
+
if (_prefabPool == null || gameObject == null) return false;
|
|
203
|
+
return _prefabPool.TryReturn(this, gameObject);
|
|
204
|
+
}
|
|
199
205
|
|
|
200
206
|
public Transform SpawnParent => _spawnParent;
|
|
201
207
|
}
|
|
@@ -207,6 +213,8 @@ namespace Amanotes.Core
|
|
|
207
213
|
void SetSpawnParent(string groupId, Transform spawnParent);
|
|
208
214
|
GameObject Get(PoolGroup group, string prefabId, Vector3 localPosition = default, Transform customParent = null);
|
|
209
215
|
void Return(PoolGroup group, GameObject gameObject);
|
|
216
|
+
/// <summary>Returns false when the instance was not checked out from this pool (silent no-op in <see cref="Return"/>).</summary>
|
|
217
|
+
bool TryReturn(PoolGroup group, GameObject gameObject);
|
|
210
218
|
IEnumerator Initialize();
|
|
211
219
|
/// <summary>
|
|
212
220
|
/// Marks the pool as shut down so all subsequent Get/Return calls no-op safely.
|
|
@@ -418,15 +426,21 @@ namespace Amanotes.Core
|
|
|
418
426
|
|
|
419
427
|
public void Return(PoolGroup group, GameObject go)
|
|
420
428
|
{
|
|
421
|
-
|
|
422
|
-
|
|
429
|
+
TryReturn(group, go);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
public bool TryReturn(PoolGroup group, GameObject go)
|
|
433
|
+
{
|
|
434
|
+
if (_isDestroyed || group == null || go == null) return false;
|
|
435
|
+
|
|
423
436
|
var instanceId = UnityObjectIdentity.GetId(go);
|
|
424
|
-
if (_instanceTypeMap.TryGetValue(instanceId, out var entry))
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
437
|
+
if (!_instanceTypeMap.TryGetValue(instanceId, out var entry))
|
|
438
|
+
return false;
|
|
439
|
+
|
|
440
|
+
entry.Return(go, transform);
|
|
441
|
+
_instanceTypeMap.Remove(instanceId);
|
|
442
|
+
_liveInstances.Remove(instanceId);
|
|
443
|
+
return true;
|
|
430
444
|
}
|
|
431
445
|
|
|
432
446
|
private void PurgeStaleInstanceMap()
|