-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoolManager.cs
81 lines (70 loc) · 2 KB
/
PoolManager.cs
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Fusion
{
public class PoolManager : MonoSingleton<PoolManager>
{
public delegate void PoolObjectResetDelegate(string poolName, PoolObject poolObject);
public static PoolObjectResetDelegate onPoolObjectReleaseCallback;
private static Transform m_Root = null;
public static Transform Root
{
get
{
if (m_Root == null)
{
m_Root = new GameObject("PoolObjectRoot").transform;
m_Root.SetParent(Instance().transform);
m_Root.gameObject.SetActive(false);
}
return m_Root;
}
}
private void Update()
{
foreach (var poolKV in Pools)
poolKV.Value.Update();
}
Dictionary<string, IPool> Pools = new Dictionary<string, IPool>();
public int PoolCount
{
get
{
return Pools.Count;
}
}
internal void Add(string poolName, IPool pool)
{
Pools.Add(poolName, pool);
}
internal IPool Remove(string poolName)
{
IPool pool = null;
if (Pools.TryGetValue(poolName, out pool))
{
Pools.Remove(poolName);
}
return pool;
}
internal IPool GetPool(string poolName)
{
IPool pool = null;
Pools.TryGetValue(poolName, out pool);
return pool;
}
public PoolObjectHolder GetObject(string poolName)
{
IPool pool = null;
if (Pools.TryGetValue(poolName, out pool))
{
return pool.Get();
}
return null;
}
public void ReleaseObject(PoolObjectHolder toRelease)
{
PoolReleaser.Release(toRelease);
}
}
}