NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Buff/GroupBuffManager.cs

70 lines
1.8 KiB
C#

using System.Collections.Generic;
using cfg.BuffCfg;
using Framework;
namespace Gameplay.Buff
{
public class GroupBuffManager
{
private static GroupBuffManager _instance;
public static GroupBuffManager instance
{
get
{
if (_instance == null)
{
_instance = new GroupBuffManager();
}
return _instance;
}
}
private Dictionary<int, GroupBuffCache> _groupMap;
private GroupBuffManager()
{
_groupMap = new Dictionary<int, GroupBuffCache>();
var allBuffs = TableManager.Instance.Tables.BuffConfig.DataList;
foreach (var buff in allBuffs)
{
var groupId = buff.GroupId;
if (groupId == 0)
{
continue;
}
if (_groupMap.TryGetValue(groupId, out var cache))
{
cache.AddBuff(buff);
}
else
{
cache = new GroupBuffCache();
cache.groupId = groupId;
cache.AddBuff(buff);
_groupMap.Add(groupId, cache);
}
}
}
public DataBuff SearchBuff(int groupId,
int level)
{
if (_groupMap.TryGetValue(groupId, out var cache))
{
return cache.SearchBuff(level);
}
return null;
}
/// <summary>
/// 清空数据
/// 理论上不需要调用
/// </summary>
public void Dispose()
{
_groupMap.Clear();
_instance = null;
}
}
}