hch
2025-09-03 bc4197c636bd2bbf011bf94cd24ebfc7b060f2d7
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
 
 
/// <summary>
/// 武将属性界面: functionOrder 用来传递武将背包索引
/// </summary>
public class HeroAllAttrWin : UIBase
{
    [SerializeField] GameObject baseAttrGroup; 
    [SerializeField] GameObject fightAttrGroup; 
    [SerializeField] GameObject fightAntiAttrGroup; 
    [SerializeField] GameObject specialAttrGroup; 
    
 
 
    Dictionary<int, Button> attrBtns = new Dictionary<int, Button>();
 
    protected override void InitComponent()
    {
        //找出所有子组件名字为attr的GameObject
        Button[] attrComponents = baseAttrGroup.GetComponentsInChildren<Button>(true)
        .Where(c => c.gameObject.name == "attr").ToArray();
 
        var attrIDList = PlayerPropertyConfig.playerPropertyDict[PlayerPropertyConfig.baseType];
        for (int i = 0; i < attrComponents.Length; i++)
        {
            if (i < attrIDList.Count)
            {
                attrComponents[i].SetActive(true);
                attrBtns.Add(attrIDList[i], attrComponents[i]);
            }
            else
            {
                attrComponents[i].SetActive(false);
            }
        }
 
        attrComponents = fightAttrGroup.GetComponentsInChildren<Button>(true)
            .Where(c => c.gameObject.name == "attr").ToArray();
        attrIDList = PlayerPropertyConfig.playerPropertyDict[PlayerPropertyConfig.fightType];
        for (int i = 0; i < attrComponents.Length; i++)
        {
            if (i < attrIDList.Count)
            {
                attrComponents[i].SetActive(true);
                attrBtns.Add(attrIDList[i], attrComponents[i]);
            }
            else
            {
                attrComponents[i].SetActive(false);
            }
        }
 
        attrComponents = fightAntiAttrGroup.GetComponentsInChildren<Button>(true)
            .Where(c => c.gameObject.name == "attr").ToArray();
        attrIDList = PlayerPropertyConfig.playerPropertyDict[PlayerPropertyConfig.fightAntiType];
        for (int i = 0; i < attrComponents.Length; i++)
        {
            if (i < attrIDList.Count)
            {
                attrComponents[i].SetActive(true);
                attrBtns.Add(attrIDList[i], attrComponents[i]);
            }
            else
            {
                attrComponents[i].SetActive(false);
            }
        }
        attrComponents = specialAttrGroup.GetComponentsInChildren<Button>(true)
            .Where(c => c.gameObject.name == "attr").ToArray();
        attrIDList = PlayerPropertyConfig.playerPropertyDict[PlayerPropertyConfig.specialType];
        for (int i = 0; i < attrComponents.Length; i++)
        {
            if (i < attrIDList.Count)
            {
                attrComponents[i].SetActive(true);
                attrBtns.Add(attrIDList[i], attrComponents[i]);
            }
            else
            {
                attrComponents[i].SetActive(false);
            }
        }
 
        //设置回调
        foreach (var kv in attrBtns)
        {
            int id = kv.Key;
            kv.Value.AddListener(() =>
            {
                SmallTipWin.showText = PlayerPropertyConfig.Get(id).desc;
                SmallTipWin.worldPos = CameraManager.uiCamera.ScreenToWorldPoint(Input.mousePosition);
                UIManager.Instance.OpenWindow<SmallTipWin>();    
            });
        }
    }
 
 
    protected override void OnPreOpen()
    {
        var item = PackManager.Instance.GetItemByIndex(PackType.Hero, functionOrder);
        if (item == null)
            return;
        var hero = HeroManager.Instance.GetHero(item.guid);
        if (hero == null)
            return;
        var dict = FightPowerManager.Instance.GetHeroTotalAttr(hero);
        foreach (var kv in attrBtns)
        {
            //每个按钮下有两个Text:name 和 value
            var id = kv.Key;
            var button = kv.Value;
            Text nameText = button.transform.Find("name").GetComponent<Text>();
            Text valueText = button.transform.Find("value").GetComponent<Text>();
 
            nameText.text = PlayerPropertyConfig.Get(id).ShowName;
            var value = dict.TryGetValue(id, out long v) ? v : 0;
            valueText.text = PlayerPropertyConfig.GetValueDescription(id, value);
        }
    }
 
 
}