|
2 | 2 |
|
3 | 3 | namespace BP.PoolIO |
4 | 4 | { |
| 5 | + /// <summary> |
| 6 | + /// ScriptableObject asset representing a pool for GameObjects. |
| 7 | + /// </summary> |
5 | 8 | [CreateAssetMenu(fileName = "Pool", menuName = "Pooling/Pool")] |
6 | 9 | public class PoolAsset : PoolResource |
7 | 10 | { |
8 | 11 | [SerializeField] private string poolName; |
9 | 12 | [SerializeField] private GameObject prefab; |
10 | | - [SerializeField] private bool reuseObjects; |
11 | 13 | [SerializeField] private int initSize; |
12 | 14 | [SerializeField] private int maxSize; |
| 15 | + [SerializeField] private bool reuseObjects; |
| 16 | + [SerializeField] private bool isPersistant; |
13 | 17 |
|
| 18 | + /// <summary> |
| 19 | + /// Gets the name of the pool. |
| 20 | + /// </summary> |
14 | 21 | public string PoolName => poolName; |
| 22 | + |
| 23 | + /// <summary> |
| 24 | + /// Gets the prefab associated with this pool. |
| 25 | + /// </summary> |
15 | 26 | public GameObject Prefab => prefab; |
16 | | - public bool ReuseObjects => reuseObjects; |
| 27 | + |
| 28 | + /// <summary> |
| 29 | + /// Gets the initial size of the pool. |
| 30 | + /// </summary> |
17 | 31 | public int InitSize => initSize; |
| 32 | + /// <summary> |
| 33 | + /// Gets the maximum size of the pool. |
| 34 | + /// </summary> |
18 | 35 | public int MaxSize => maxSize; |
19 | 36 |
|
20 | | - private IPoolable poolRef; |
| 37 | + /// <summary> |
| 38 | + /// Gets a value indicating whether objects in the pool should be reused. |
| 39 | + /// </summary> |
| 40 | + public bool ReuseObjects => reuseObjects; |
21 | 41 |
|
22 | | - public override void Init() |
23 | | - { |
24 | | - if (PoolUtils.IsNull(poolRef)) |
25 | | - { |
26 | | - poolRef = GetPool(); |
27 | | - } |
28 | | - } |
| 42 | + /// <summary> |
| 43 | + /// Gets a value indicating whether the pool should persist across scene loads. |
| 44 | + /// </summary> |
| 45 | + public bool IsPersistant => isPersistant; |
| 46 | + |
| 47 | + private IPool poolRef; |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Retrieves a GameObject from the pool. |
| 51 | + /// </summary> |
| 52 | + /// <returns>The pooled GameObject.</returns> |
29 | 53 | public override GameObject Get() => GetPool().Get(); |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Releases a GameObject back into the pool. |
| 57 | + /// </summary> |
| 58 | + /// <param name="gameObject">The GameObject to release.</param> |
| 59 | + /// <returns>True if the object was successfully released; otherwise, false.</returns> |
30 | 60 | public override bool Release(GameObject gameObject) => poolRef?.Release(gameObject) ?? false; |
31 | | - private IPoolable GetPool() |
| 61 | + |
| 62 | + /// <summary> |
| 63 | + /// Gets the pool instance, creating it if necessary. |
| 64 | + /// </summary> |
| 65 | + /// <returns>The pool instance implementing IPoolable.</returns> |
| 66 | + private IPool GetPool() |
32 | 67 | { |
33 | 68 | if (PoolUtils.IsNull(poolRef)) |
34 | 69 | { |
|
0 commit comments