lcy
2026-07-16 34179ffa10e510ba71522cb2bd1fd978b7fcbbe1
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
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;
    }
}