Skip to content

Commit c45de89

Browse files
committed
Init
1 parent e9e9938 commit c45de89

13 files changed

+522
-6
lines changed

Diff for: README.md

+69-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,75 @@
1+
<p align="left">
2+
<a>
3+
<img alt="Made With Unity" src="https://img.shields.io/badge/made%20with-Unity-57b9d3.svg?logo=Unity">
4+
</a>
5+
<a>
6+
<img alt="License" src="https://img.shields.io/github/license/wolf-package/object-pooling-unity?logo=github">
7+
</a>
8+
<a>
9+
<img alt="Last Commit" src="https://img.shields.io/github/last-commit/wolf-package/object-pooling-unity?logo=Mapbox&color=orange">
10+
</a>
11+
<a>
12+
<img alt="Repo Size" src="https://img.shields.io/github/repo-size/wolf-package/object-pooling-unity?logo=VirtualBox">
13+
</a>
14+
<a>
15+
<img alt="Last Release" src="https://img.shields.io/github/v/release/wolf-package/object-pooling-unity?include_prereleases&logo=Dropbox&color=yellow">
16+
</a>
17+
</p>
18+
19+
20+
121
## How To Install
222

323
### Add the line below to `Packages/manifest.json`
424

5-
for version `x.x.x`
25+
for version `1.0.0`
26+
```csharp
27+
"com.wolf-package.object-pooling":"https://github.com/wolf-package/object-pooling-unity.git#1.0.0",
28+
```
29+
## Use
30+
31+
- Init Pool
32+
33+
```csharp
34+
Pool.InitPool();
35+
```
36+
37+
- Spawn/DeSpawn Object
38+
639
```csharp
7-
"com.virtuesky._package_name_":"https://github.com/VirtueSky/_package_name_.git#x.x.x",
40+
41+
public GameObject prefab;
42+
43+
private GameObject ins;
44+
45+
void SpawnIns()
46+
{
47+
ins = Pool.Spawn(prefab);
48+
}
49+
50+
void DeSpawnIns()
51+
{
52+
Pool.DeSpawn(ins);
53+
}
54+
855
```
56+
57+
Or
58+
59+
```csharp
60+
61+
public GameObject prefab;
62+
63+
private GameObject ins;
64+
65+
void SpawnIns()
66+
{
67+
ins = prefab.Spawn();
68+
}
69+
70+
void DeSpawnIns()
71+
{
72+
ins.DeSpawn();
73+
}
74+
75+
```

Diff for: README.md.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Runtime.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Runtime/Pool.cs

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
using UnityEngine;
2+
3+
namespace VirtueSky.ObjectPooling
4+
{
5+
public static class Pool
6+
{
7+
private static PoolHandle _poolHandle;
8+
9+
public static void InitPool()
10+
{
11+
if (_poolHandle == null)
12+
{
13+
_poolHandle = new PoolHandle();
14+
_poolHandle.Initialize();
15+
}
16+
}
17+
18+
19+
#region API Spawn
20+
21+
public static void PreSpawn(this PoolData poolData)
22+
{
23+
if (_poolHandle == null)
24+
{
25+
Debug.Log($"Please init pool before {System.Reflection.MethodBase.GetCurrentMethod()?.Name}");
26+
return;
27+
}
28+
29+
_poolHandle.PreSpawn(poolData);
30+
}
31+
32+
public static GameObject Spawn(this GameObject prefab, Transform parent = null, bool worldPositionStays = true)
33+
{
34+
if (_poolHandle == null)
35+
{
36+
Debug.Log($"Please init pool before {System.Reflection.MethodBase.GetCurrentMethod()?.Name}");
37+
return null;
38+
}
39+
40+
return _poolHandle.Spawn(prefab, parent, worldPositionStays);
41+
}
42+
43+
public static T Spawn<T>(this T type, Transform parent = null, bool worldPositionStays = true)
44+
where T : Component
45+
{
46+
if (_poolHandle == null)
47+
{
48+
Debug.Log($"Please init pool before {System.Reflection.MethodBase.GetCurrentMethod()?.Name}");
49+
return null;
50+
}
51+
52+
return _poolHandle.Spawn(type, parent, worldPositionStays).GetComponent<T>();
53+
}
54+
55+
public static GameObject Spawn(this GameObject prefab, Vector3 position, Quaternion rotation,
56+
Transform parent = null,
57+
bool worldPositionStays = true)
58+
{
59+
if (_poolHandle == null)
60+
{
61+
Debug.Log($"Please init pool before {System.Reflection.MethodBase.GetCurrentMethod()?.Name}");
62+
return null;
63+
}
64+
65+
return _poolHandle.Spawn(prefab, position, rotation, parent, worldPositionStays);
66+
}
67+
68+
public static T Spawn<T>(this T type, Vector3 position, Quaternion rotation, Transform parent = null,
69+
bool worldPositionStays = true)
70+
where T : Component
71+
{
72+
if (_poolHandle == null)
73+
{
74+
Debug.Log($"Please init pool before {System.Reflection.MethodBase.GetCurrentMethod()?.Name}");
75+
return null;
76+
}
77+
78+
return _poolHandle.Spawn(type, position, rotation, parent, worldPositionStays)
79+
.GetComponent<T>();
80+
}
81+
82+
#endregion
83+
84+
#region API DeSpawn
85+
86+
public static void DeSpawn(this GameObject gameObject, bool destroy = false, bool worldPositionStays = true)
87+
{
88+
if (_poolHandle == null)
89+
{
90+
Debug.Log($"Please init pool before {System.Reflection.MethodBase.GetCurrentMethod()?.Name}");
91+
return;
92+
}
93+
94+
_poolHandle.DeSpawn(gameObject, destroy, worldPositionStays);
95+
}
96+
97+
public static void DeSpawn<T>(this T type, bool destroy = false, bool worldPositionStays = true)
98+
where T : Component
99+
{
100+
if (_poolHandle == null)
101+
{
102+
Debug.Log($"Please init pool before {System.Reflection.MethodBase.GetCurrentMethod()?.Name}");
103+
return;
104+
}
105+
106+
_poolHandle.DeSpawn(type, destroy, worldPositionStays);
107+
}
108+
109+
public static void DeSpawnAll()
110+
{
111+
if (_poolHandle == null)
112+
{
113+
Debug.Log($"Please init pool before {System.Reflection.MethodBase.GetCurrentMethod()?.Name}");
114+
return;
115+
}
116+
117+
_poolHandle.DeSpawnAll();
118+
}
119+
120+
#endregion
121+
122+
#region API Destroy
123+
124+
public static void DestroyAll()
125+
{
126+
if (_poolHandle == null)
127+
{
128+
Debug.Log($"Please init pool before {System.Reflection.MethodBase.GetCurrentMethod()?.Name}");
129+
return;
130+
}
131+
132+
_poolHandle.DestroyAll();
133+
}
134+
135+
public static void DestroyAllWaitPools()
136+
{
137+
if (_poolHandle == null)
138+
{
139+
Debug.Log($"Please init pool before {System.Reflection.MethodBase.GetCurrentMethod()?.Name}");
140+
return;
141+
}
142+
143+
_poolHandle.DestroyAllWaitPools();
144+
}
145+
146+
#endregion
147+
}
148+
}

Diff for: Runtime/Pool.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Runtime/PoolData.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using UnityEngine;
3+
4+
namespace VirtueSky.ObjectPooling
5+
{
6+
[Serializable]
7+
public class PoolData
8+
{
9+
public GameObject prefab;
10+
public int count;
11+
}
12+
}

Diff for: Runtime/PoolData.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)