-
Notifications
You must be signed in to change notification settings - Fork 0
/
AllCacheController.cs
62 lines (55 loc) · 1.75 KB
/
AllCacheController.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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class enemyItem
{
public enemyType _type;
public GameObject _go;
}
public class AllCacheController : MonoBehaviour {
private Dictionary<enemyType,CacheController<GameObject,GameObject>> cacheControllerDic;
public List<enemyItem> enemyItemList;
public static AllCacheController instance;
void Awake()
{
instance = this;
cacheControllerDic = new Dictionary<enemyType, CacheController<GameObject, GameObject>>();
}
public GameObject popItem(enemyType _type)
{
if (cacheControllerDic.ContainsKey(_type))
return cacheControllerDic[_type].popItem();
else
{
for(int i = 0; i < enemyItemList.Count; i++)
{
if (enemyItemList[i]._type == _type)
{
EnemyCache cache = new EnemyCache(enemyItemList[i]._go, enemyItemList[i]._go);
cache.init(2,10);
cacheControllerDic.Add(_type, cache);
return cache.popItem();
}
}
Debug.LogError("找不到此类型的Go");
return null;
}
}
public void pushBackItem(GameObject _go)
{
if(_go == null)
return;
enemyType temp = _go.GetComponent<ATKandDamage>().type;
if (cacheControllerDic.ContainsKey(temp))
cacheControllerDic[temp].pushBackItem(_go);
else
Debug.LogError("不存在该Go对象对象池");
}
public void discardAll()
{
foreach (enemyType key in cacheControllerDic.Keys)
cacheControllerDic[key].discard();
Destroy(this);
}
}