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
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using TowerDefense.Level;
 
/**
 * 无尽模式buff预览
 * @Author: chenxin
 * @Date: 2020-11-12 10:01:36
 */
namespace KTGMGemClient
{
    public class EndlessBuffPreview : MonoBehaviour
    {
        /// <summary>
        /// buff预览界面
        /// </summary>
        public GameObject Panel;
 
        public GameObject Content;
 
        /// <summary>
        /// buff预览界面返回按钮
        /// </summary>
        public Button BackBtn;
 
        /// <summary>
        /// 未获得buff提示文字
        /// </summary>
        public Text NoBuffText;
 
        private float preTimeScale;
 
        // Start is called before the first frame update
        private void Start()
        {
            GetComponent<Button>().onClick.AddListener(OnClick);
            BackBtn.onClick.AddListener(HideBuffPreview);
            EventCenter.Ins.Add((int)KTGMGemClient.EventType.EndlessBuffRefresh, Refresh);
            Panel.SetActive(false);
        }
 
        public void OnClick()
        {
            if (GameConfig.IsNewbie) return;
 
            ShowBuffPreview();
        }
 
        private void Refresh()
        {
            if (!Panel.activeInHierarchy) return;
 
            ClearContent();
 
            List<EndlessBuffConfig> buffList = EndlessBuffManager.instance.BuffList;
 
            if (buffList.Count == 0)
            {
                NoBuffText.gameObject.SetActive(true);
                return;
            }
 
            NoBuffText.gameObject.SetActive(false);
 
            for (int i = 0; i < buffList.Count; ++i)
            {
                GameObject prefab = Resources.Load<GameObject>("UI/BuffPreview/BuffItem");
                GameObject item = Instantiate(prefab);
                item.transform.SetParent(Content.transform, false);
 
                SelectBuffIcon buffSelect = item.GetComponent<SelectBuffIcon>();
                buffSelect.SetIcon(buffList[i].Config.image);
                buffSelect.SetQuality(buffList[i].Config.rare);
                buffSelect.SetName(buffList[i].Config.name);
                buffSelect.SetEffect(buffList[i].Config.brief);
                buffSelect.SetRare(buffList[i].Config.rare);
            }
        }
 
        private void ClearContent()
        {
            for (int i = Content.transform.childCount - 1; i >= 0; --i)
            {
                Destroy(Content.transform.GetChild(i).gameObject);
            }
        }
 
        private void ShowBuffPreview()
        {
            preTimeScale = Time.timeScale;
            Time.timeScale = 0;
            Panel.SetActive(true);
            Refresh();
            AudioSourceManager.Ins.StopBGAudio();
        }
 
        private void HideBuffPreview()
        {
            Time.timeScale = preTimeScale;
            Panel.SetActive(false);
            AudioSourceManager.Ins.RestartBGAudio();
 
        }
    }
}