using System.Collections.Generic;
|
using UnityEngine;
|
|
public partial class ActTypeConfig : ConfigBase<int, ActTypeConfig>
|
{
|
// 注:CfgID 从 1 开始,0 用作 GetCfgID/TryGetCfgID 的"未命中"占位返回值
|
//<功能类型,<模板ID,配置ID>>
|
static Dictionary<int, Dictionary<int, int>> infoDict = new Dictionary<int, Dictionary<int, int>>();
|
|
// 配置行解析完成回调:建立 ActFuncType → ActTempID → CfgID 二级索引,重复组合会告警
|
protected override void OnConfigParseCompleted()
|
{
|
if (!infoDict.ContainsKey(ActFuncType))
|
infoDict[ActFuncType] = new Dictionary<int, int>();
|
if (infoDict[ActFuncType].ContainsKey(ActTempID))
|
{
|
Debug.LogError(typeof(ActTypeConfig).Name + " 重复的 ActFuncType " + ActFuncType + " ActTempID " + ActTempID + " 旧CfgID " + infoDict[ActFuncType][ActTempID] + " 新CfgID " + CfgID);
|
}
|
infoDict[ActFuncType][ActTempID] = CfgID;
|
}
|
|
// 通过活动功能类型和模板ID查询配置ID,未命中返回 0
|
public static int GetCfgID(int actFuncType, int actTempID)
|
{
|
return infoDict.TryGetValue(actFuncType, out var info) && info.TryGetValue(actTempID, out var cfgID) ? cfgID : 0;
|
}
|
|
// 尝试通过活动功能类型和模板ID查询配置ID,命中返回 true
|
public static bool TryGetCfgID(int actFuncType, int actTempID, out int cfgID)
|
{
|
cfgID = 0;
|
return infoDict != null && infoDict.TryGetValue(actFuncType, out var info) && info.TryGetValue(actTempID, out cfgID);
|
}
|
|
// 通过活动功能类型和模板ID获取配置,未命中返回 null
|
public static ActTypeConfig GetConfig(int actFuncType, int actTempID)
|
{
|
int cfgID = GetCfgID(actFuncType, actTempID);
|
return cfgID == 0 ? null : Get(cfgID);
|
}
|
|
// 通过配置ID获取配置,未命中返回 false
|
public static bool TryGetConfig(int cfgID, out ActTypeConfig config)
|
{
|
config = null;
|
if (!HasKey(cfgID))
|
return false;
|
config = Get(cfgID);
|
return true;
|
}
|
|
// 通过活动功能类型和模板ID获取配置,未命中返回 false
|
public static bool TryGetConfig(int actFuncType, int actTempID, out ActTypeConfig config)
|
{
|
config = null;
|
if (!TryGetCfgID(actFuncType, actTempID, out int cfgID))
|
return false;
|
return TryGetConfig(cfgID, out config);
|
}
|
|
// 获取指定活动功能类型下的全部配置ID
|
public static List<int> GetCfgIDsByFuncType(int actFuncType)
|
{
|
List<int> result = new List<int>();
|
if (infoDict.TryGetValue(actFuncType, out var info))
|
{
|
result.AddRange(info.Values);
|
}
|
return result;
|
}
|
}
|