yyl
15 小时以前 ad14e2586cd13c52b30e1cc481724a1e09407f6a
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
using System.Collections.Generic;
using UnityEngine;
using LitJson;
 
public partial class HeroConfig : ConfigBase<int, HeroConfig>
{
    public Dictionary<HeroAttrType, int> inheritPropertiesDict = new Dictionary<HeroAttrType, int>();
 
    protected override void OnConfigParseCompleted()
    {
        base.OnConfigParseCompleted();
 
        inheritPropertiesDict.Clear();
 
        inheritPropertiesDict.Add(HeroAttrType.attack, AtkInheritPer);
        inheritPropertiesDict.Add(HeroAttrType.defense, DefInheritPer);
        inheritPropertiesDict.Add(HeroAttrType.hp, HPInheritPer);
 
 
        // json格式
        // {"属性ID":值, ...}
        // 属性ID对应属性条目表的ID
        // 有值的配即可,没有配置的属性默认0
        JsonData jsonData = JsonMapper.ToObject(BatAttrDict);
 
        foreach (var attrId in jsonData.Keys)
        {
            if (int.TryParse(attrId.ToString(), out int attrTypeId))
            {
                HeroAttrType attrType = (HeroAttrType)attrTypeId;
                if (jsonData[attrId] != null && int.TryParse(jsonData[attrId].ToString(), out int value))
                {
                    if (inheritPropertiesDict.ContainsKey(attrType))
                    {
                        Debug.LogError($"HeroTalentConfig: 属性 {attrType} 已经存在,无法重复添加。请检查配置文件。");
                    }
                    else
                    {
                        inheritPropertiesDict.Add(attrType, value);
                    }
                }
            }
        }
    }
 
    public int GetInheritPercent(HeroAttrType attrType)
    {
        if (inheritPropertiesDict.TryGetValue(attrType, out int perc))
        {
            return perc;
        }
 
        return 0;
    }
}