Skip to content

Commit 07b803f

Browse files
committed
Renamed to RefPool and improved README
1 parent aa1e311 commit 07b803f

36 files changed

+377
-253
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "BP.PoolIO.Editor",
3-
"rootNamespace": "BP.PoolIO.Editor",
2+
"name": "BP.RefPool.Editor",
3+
"rootNamespace": "BP.RefPool.Editor",
44
"references": [
55
"GUID:5df53463e12a5c24183fa4fbd6737925"
66
],

Editor/EditorUtil.cs

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,49 @@
1-
using BP.PoolIO;
21
using UnityEditor;
32
using UnityEngine;
43

5-
public static class EditorUtil
4+
namespace BP.RefPool.Editor
65
{
7-
8-
[MenuItem("GameObject/Pools/Pool", false, 10)]
9-
public static void CreatePool(MenuCommand menuCommand)
6+
public static class EditorUtil
107
{
11-
GameObject go = new("Pool");
12-
go.AddComponent<Pool>();
13-
EditorCreeate(menuCommand, go);
14-
}
158

16-
[MenuItem("GameObject/Pools/Group", false, 10)]
17-
public static void CreateGroup(MenuCommand menuCommand)
18-
{
19-
GameObject root = new("Group", typeof(PoolGroup));
20-
var rootGroup = root.GetComponent<PoolGroup>();
21-
for (int i = 0; i < 3; i++)
9+
[MenuItem("GameObject/RefPool/Pool", false, 10)]
10+
public static void CreatePool(MenuCommand menuCommand)
2211
{
23-
GameObject child = new($"Pool #{i + 1}", typeof(Pool));
24-
child.transform.SetParent(root.transform);
25-
rootGroup.AddPool(child.GetComponent<Pool>());
12+
GameObject go = new("Pool");
13+
go.AddComponent<Pool>();
14+
EditorCreeate(menuCommand, go);
2615
}
27-
EditorCreeate(menuCommand, root);
28-
}
2916

30-
private static void EditorCreeate(MenuCommand menuCommand, params GameObject[] gameobjects)
31-
{
32-
foreach (var go in gameobjects)
17+
[MenuItem("GameObject/RefPool/Group", false, 10)]
18+
public static void CreateGroup(MenuCommand menuCommand)
19+
{
20+
GameObject root = new("Group", typeof(PoolGroup));
21+
var rootGroup = root.GetComponent<PoolGroup>();
22+
for (int i = 0; i < 3; i++)
23+
{
24+
GameObject child = new($"Pool #{i + 1}", typeof(Pool));
25+
child.transform.SetParent(root.transform);
26+
rootGroup.AddPool(child.GetComponent<Pool>());
27+
}
28+
EditorCreeate(menuCommand, root);
29+
}
30+
31+
32+
[MenuItem("GameObject/RefPool/Spawner", false, 10)]
33+
public static void CreateSpawner(MenuCommand menuCommand)
34+
{
35+
GameObject root = new("Spawner", typeof(PoolSpawner));
36+
EditorCreeate(menuCommand, root);
37+
}
38+
39+
private static void EditorCreeate(MenuCommand menuCommand, params GameObject[] gameobjects)
3340
{
34-
GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
35-
Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
41+
foreach (var go in gameobjects)
42+
{
43+
GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
44+
Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
45+
}
46+
Selection.objects = gameobjects;
3647
}
37-
Selection.objects = gameobjects;
3848
}
39-
}
49+
}

README.md

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,98 @@
11
# RefPool
2-
A simple unity package utilizing scriptable objects to link Pools and PoolGroups across scenes.
2+
[![GitHub Repo stars](https://img.shields.io/github/stars/BluePixelDev/refpool?style=flat-square)](https://github.com/BluePixelDev/refpool/stargazers)
3+
[![GitHub last commit](https://img.shields.io/github/last-commit/BluePixelDev/refpool?style=flat-square)](https://github.com/BluePixelDev/refpool/commits/main)
4+
[![GitHub issues](https://img.shields.io/github/issues/bluepixeldev/refpool?style=flat-square)](https://github.com/bluepixeldev/refpool/issues)
5+
[![Unity Version](https://img.shields.io/badge/unity-6.0%2B-green?style=flat-square)](https://unity.com/releases/editor)
6+
7+
**RefPool** is a lightweight, ScriptableObject-driven pooling system for Unity 6.0 and above.
8+
It enables clean, efficient reuse of GameObjects across scenes without relying on global registries.
9+
10+
## Features
11+
- ScriptableObject-based pool references for cross-scene linking
12+
- Lazy pool initialization and automatic cleanup on unload
13+
- Efficient memory management through shared pooling
14+
- Supports runtime spawning with configurable options such as spawn rate, position overrides, and randomization
15+
- Clean integration with Unity’s component model
16+
- Extendable through custom `PoolResource` implementations for advanced pooling behaviors
17+
18+
## Installation
19+
20+
### Unity Package Manager (via Git URL)
21+
22+
1. Open your Unity project
23+
2. Go to `Packages/manifest.json`
24+
3. Add the following line to the `dependencies` block:
25+
26+
```json
27+
"com.bluepixeldev.refpool": "https://github.com/bluepixeldev/refpool.git"
28+
```
29+
30+
### Manual Import
31+
32+
Clone or download this repository and move the `RefPool` folder into your project's `Assets` directory.
33+
34+
## Usage
35+
36+
### Create a Pool Resource
37+
38+
1. Right-click in the `Project` window
39+
2. Select `Create > RefPool > Pool or Pool Group`
40+
3. Assign the prefab and configure pool size, increment size, and other settings
41+
42+
### Add a RefPoolSpawner
43+
44+
1. Attach the `RefPoolSpawner` component to a GameObject
45+
2. Assign the `PoolResource` you created
46+
3. Configure spawn behavior as needed
47+
48+
### Trigger Spawning
49+
50+
You can trigger pooled object spawning manually or automatically:
51+
52+
```csharp
53+
[SerializeField] private PoolSpawner spawner;
54+
55+
void SomeEventTrigger()
56+
{
57+
spawner.Spawn();
58+
}
59+
```
60+
61+
### Extending with Custom Pool Behaviors
62+
63+
RefPool allows you to implement custom pooling logic by extending the `PoolResource` class. This enables advanced use cases such as dynamic pool resizing, custom initialization, or specialized cleanup logic.
64+
65+
Here’s an example of a custom `PoolResource`:
66+
67+
```csharp
68+
using UnityEngine;
69+
70+
namespace BP.RefPool
71+
{
72+
public class CustomPoolResource : PoolResource
73+
{
74+
public override void Initialize()
75+
{
76+
// Custom initialization logic
77+
}
78+
79+
public override GameObject Get()
80+
{
81+
// Custom logic for retrieving a GameObject from the pool
82+
return null;
83+
}
84+
85+
public override bool Release(GameObject gameObject)
86+
{
87+
// Custom logic for releasing a GameObject back to the pool
88+
return true;
89+
}
90+
}
91+
}
92+
```
93+
94+
This flexibility allows you to tailor the pooling system to your specific project requirements.
95+
96+
## Contributing
97+
98+
Pull requests and issues are welcome. If you encounter a bug or have a feature suggestion, please open an issue on GitHub.

reamde.md.meta renamed to README.md.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Asset/PoolAsset.cs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
using UnityEngine;
22

3-
namespace BP.PoolIO
3+
namespace BP.RefPool
44
{
55
/// <summary>
66
/// ScriptableObject asset representing a pool for GameObjects.
77
/// </summary>
8-
[CreateAssetMenu(fileName = "Pool", menuName = "Pooling/Pool")]
8+
[CreateAssetMenu(fileName = "Pool", menuName = "RefPool/Pool")]
99
public class PoolAsset : PoolResource
1010
{
1111
[SerializeField] private string poolName;
1212
[SerializeField] private GameObject prefab;
1313
[SerializeField] private int initSize;
1414
[SerializeField] private int maxSize;
1515
[SerializeField] private bool reuseObjects;
16-
[SerializeField] private bool isPersistant;
16+
[SerializeField] private bool isPersistent;
1717

1818
/// <summary>
1919
/// Gets the name of the pool.
@@ -42,21 +42,19 @@ public class PoolAsset : PoolResource
4242
/// <summary>
4343
/// Gets a value indicating whether the pool should persist across scene loads.
4444
/// </summary>
45-
public bool IsPersistant => isPersistant;
45+
public bool IsPersistent => isPersistent;
4646

4747
private IPool poolRef;
4848

49-
/// <summary>
50-
/// Retrieves a GameObject from the pool.
51-
/// </summary>
52-
/// <returns>The pooled GameObject.</returns>
49+
public override void Initialize()
50+
{
51+
if (PoolUtils.IsNull(poolRef))
52+
{
53+
poolRef = PoolUtils.CreatePool(this);
54+
poolRef.Initialize();
55+
}
56+
}
5357
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>
6058
public override bool Release(GameObject gameObject) => poolRef?.Release(gameObject) ?? false;
6159

6260
/// <summary>
@@ -65,11 +63,7 @@ public class PoolAsset : PoolResource
6563
/// <returns>The pool instance implementing IPoolable.</returns>
6664
private IPool GetPool()
6765
{
68-
if (PoolUtils.IsNull(poolRef))
69-
{
70-
poolRef = PoolUtils.CreatePool(this);
71-
}
72-
66+
Initialize();
7367
return poolRef;
7468
}
7569
}

Runtime/Asset/PoolGroupAsset.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using UnityEngine;
22

3-
namespace BP.PoolIO
3+
namespace BP.RefPool
44
{
55
/// <summary>
66
/// Enumeration for selecting the pooling strategy.
@@ -15,7 +15,7 @@ public enum PoolPickMode
1515
/// <summary>
1616
/// ScriptableObject asset representing a group of pools.
1717
/// </summary>
18-
[CreateAssetMenu(fileName = "PoolGroup", menuName = "Pooling/PoolGroup")]
18+
[CreateAssetMenu(fileName = "PoolGroup", menuName = "RefPool/Pool Group")]
1919
public class PoolGroupAsset : PoolResource
2020
{
2121
[SerializeField] private string groupName;
@@ -45,6 +45,14 @@ public class PoolGroupAsset : PoolResource
4545

4646
private PoolGroup groupRef;
4747

48+
public override void Initialize()
49+
{
50+
if (PoolUtils.IsNull(groupRef))
51+
{
52+
groupRef = PoolUtils.CreatePoolGroup(this);
53+
groupRef.Initialize();
54+
}
55+
}
4856
public override GameObject Get() => GetPoolGroup().Get();
4957
public override bool Release(GameObject gameObject)
5058
{
@@ -53,10 +61,7 @@ public override bool Release(GameObject gameObject)
5361
}
5462
private PoolGroup GetPoolGroup()
5563
{
56-
if (PoolUtils.IsNull(groupRef))
57-
{
58-
groupRef = PoolUtils.CreatePoolGroup(this);
59-
}
64+
Initialize();
6065
return groupRef;
6166
}
6267
}

Runtime/Asset/PoolResource.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "BP.PoolIO",
3-
"rootNamespace": "BP.PoolIO",
2+
"name": "BP.RefPool",
3+
"rootNamespace": "BP.RefPool",
44
"references": [],
55
"includePlatforms": [],
66
"excludePlatforms": [],

0 commit comments

Comments
 (0)