wangguan
2020-11-18 046745bcbb2caefa813eb03f212842bdf8ab62c4
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
using UnityEngine.UI;
using System.Collections;
using TowerDefense.Level;
using System.Collections.Generic;
using UnityEngine;
 
/**
 * 无尽模式buff预览
 * @Author: chenxin
 * @Date: 2020-11-12 10:01:36
 */
namespace KTGMGemClient
{
    public class EndlessBuffPreview : MonoBehaviour
    {
        public GameObject Panel;
 
        private bool isShow;
 
        private string iconPath = "UI/Endless/BuffPreviewIcon/buff_";
 
        public List<GameObject> ItemList;
 
        public List<Image> IconList;
 
        public List<Text> TextList;
 
        private string[] elementNameArr = { "火", "水", "木" };
 
        // Start is called before the first frame update
        private void Start()
        {
            GetComponent<Button>().onClick.AddListener(OnClick);
            EventCenter.Ins.Add((int)KTGMGemClient.EventType.EndlessBuffRefresh, Refresh);
            ShowPanel();
        }
 
        public void OnClick()
        {
            ShowPanel();
        }
 
        private void ShowPanel()
        {
            if (isShow)
                Refresh();
            Panel.SetActive(isShow);
            isShow = !isShow;
        }
 
        private void Refresh()
        {
            List<EndlessBuffConfig> buffList = EndlessBuffManager.instance.BuffList;
            // 0.火  1.水  2.木
            int[] addArr = { 0, 0, 0 };
 
            for (int i = 0; i < buffList.Count; ++i)
            {
                // 只统计了加攻击力的
                if (buffList[i].EffectType != EndlessBuffEffectType.AttackAdd) continue;
 
                switch (buffList[i].UseTarget)
                {
                    case EndlessBuffUseTarget.All:
                        addArr[0] += (int)buffList[i].Config.buff_effect[1];
                        addArr[1] += (int)buffList[i].Config.buff_effect[1];
                        addArr[2] += (int)buffList[i].Config.buff_effect[1];
                        break;
                    case EndlessBuffUseTarget.Element:
                        addArr[(int)buffList[i].Config.target_type[1] - 1] += (int)buffList[i].Config.buff_effect[1];
                        break;
                    case EndlessBuffUseTarget.Designated:
                        break;
                }
            }
 
            int count = 0;
 
            for (int i = 0; i < addArr.Length; ++i)
            {
                if (addArr[i] == 0) continue;
 
                ItemList[count].SetActive(true);
                Sprite sp = Resources.Load<Sprite>($"{iconPath}{i + 1}");
                IconList[count].sprite = sp;
                TextList[count].text = $"{elementNameArr[i]}精灵攻击+{addArr[i]}%";
                ++count;
            }
 
            for (; count < 3; ++count)
            {
                ItemList[count].SetActive(false);
            }
        }
    }
}