public void AddBuff(BuffName buffName, int layer) { Type type = Type.GetType(buffName.ToString()); object obj = Activator.CreateInstance(type, true); if (obj == null) { Debug.Log("No Card for" + buffName.ToString()); return; } AddBuff((Buff)obj); BuffAddLayer(buffName, layer); View.GetInstance().ShowBuff(self); }
public BuffData LoadData(BuffName tag) { ; Debug.Log("尝试读取:" + tag.ToString()); int index = -1, minLRU = INF; bool findFlag = false, evictFlag = true; BuffData res = null; for (int i = 0; i < dataCells.Length; i++) { //如果不为空 if (dataCells[i].IsValid) { //如果标签一致 if (dataCells[i].Tag == tag) { findFlag = true; res = dataCells[i].Object; dataCells[i].LRU = INF; Debug.Log("缓存命中!!!"); } //标签不一致 else { //LRU减一 dataCells[i].LRU--; //如果需要evict并且没有find,则需要搜索最小LRU if (evictFlag && !findFlag && minLRU > dataCells[i].LRU) { minLRU = dataCells[i].LRU; index = i; } } } //单元格为空时,如果需要evict,则记录该空格为可替换的空格 else if (evictFlag && !findFlag) { evictFlag = false; index = i; } } if (!findFlag) { if (evictFlag) { Debug.Log("冲突不命中"); } else { Debug.Log("冷不命中"); } dataCells[index].IsValid = true; dataCells[index].LRU = INF; dataCells[index].Tag = tag; dataCells[index].Object = Resources.Load <BuffData>(GameDB.Instance.buffDataPath.paths[(int)tag]); res = dataCells[index].Object; } return(res); }
public void BuffAddLayer(BuffName buffName, int layer = 1) { foreach (Buff buff in buffs) { if (buff.ToString() == buffName.ToString()) { buff.Layer += layer; return; } } }