-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoolManager.cs
More file actions
48 lines (40 loc) · 1.41 KB
/
PoolManager.cs
File metadata and controls
48 lines (40 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Collections.Generic;
using System.Linq;
namespace Subtegral.PoolUtility
{
public class PoolManager
{
private List<GenericPool<PoolableObject>> pools;
private static PoolManager _instance;
public static PoolManager GetInstance()
{
if (_instance == null)
{
_instance = new PoolManager();
}
return _instance;
}
public static void DestroyInstance()
{
_instance = new PoolManager();
}
public static void GenerateNewPool<T>(T target,int size=5) where T : PoolableObject
{
if (_instance.pools.Any(x => x.GetPoolType() == target))
throw new System.Exception("This type is already pooled!");
_instance.pools.Add(new GenericPool<PoolableObject>(target,size));
}
public static T RequestSpawnForType<T>(T targetType, SpawnDataContainer container) where T : PoolableObject
{
return _instance.pools.Find(x => x.GetPoolType() == targetType).Spawn(container) as T;
}
public static void DespawnObject<T>(T targetType,T instance) where T : PoolableObject
{
_instance.pools.Find(x=>x.GetPoolType()==targetType).Despawn(instance);
}
private PoolManager()
{
pools = new List<GenericPool<PoolableObject>>();
}
}
}