wangguan
2020-10-22 7a007a8d1e7cd712fa4571efdbc3f2eba7a7e4d0
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
using Protobuf;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Core.Utilities;
using TowerDefense.Level;
 
/**
 * 无尽模式查看已经获得道具
 * @Author: chenxin
 * @Date: 2020-10-19 16:53:29
 */
namespace KTGMGemClient
{
    public class EndlessViewObtainedProps : Singleton<EndlessViewObtainedProps>
    {
        /// <summary>
        /// 奖励信息界面
        /// </summary>
        public GameObject RewardInfoUI;
 
        /// <summary>
        /// 初级宝箱文本
        /// </summary>
        public Text PrimaryTreasure;
 
        /// <summary>
        /// 中级宝箱文本
        /// </summary>
        public Text MiddleTreasure;
 
        /// <summary>
        /// 高级宝箱文本
        /// </summary>
        public Text AdvancedTreasure;
 
        /// <summary>
        /// 钻石文本
        /// </summary>
        public Text Gold;
 
        /// <summary>
        /// 奖励信息界面是否正在展示
        /// </summary>
        private bool isShow;
 
        private int[] countArr = { 0, 0, 0, 0 };
 
        // Start is called before the first frame update
        private void Start()
        {
            EndlessDropManager.instance.ObtainDropEvent += OnObtainDrop;
        }
 
        private void OnEnable()
        {
            RewardInfoUI.SetActive(false);
            isShow = false;
        }
 
        public void OnClick()
        {
            isShow = !isShow;
 
            if (isShow) Refresh();
 
            RewardInfoUI.SetActive(isShow);
        }
 
        /// <summary>
        /// 刷新掉落奖励界面
        /// </summary>
        private void Refresh()
        {
            CalculateCount();
            PrimaryTreasure.text = $"初级宝箱×{countArr[0]}";
            MiddleTreasure.text = $"中级宝箱×{countArr[1]}";
            AdvancedTreasure.text = $"高级宝箱×{countArr[2]}";
            Gold.text = $"钻石×{countArr[3]}";
        }
 
        /// <summary>
        /// 重新统计数量
        /// </summary>
        private void CalculateCount()
        {
            // 统计数量
            int[] arr = { 0, 0, 0, 0 };
            List<EndlessDrop> list = EndlessDropManager.instance.GetAllObtainedDrop();
 
            for (int i = 0; i < list.Count; ++i)
            {
                switch (list[i].Reward.type)
                {
                    case CURRENCY.Gold:
                        arr[3] += list[i].Reward.count;
                        break;
                    case CURRENCY.Box:
                        arr[list[i].Reward.id - 1] += list[i].Reward.count;
                        break;
                }
            }
 
            countArr = arr;
        }
 
        /// <summary>
        /// 获得掉落
        /// </summary>
        public void OnObtainDrop(EndlessDrop data)
        {
            if (RewardInfoUI.activeInHierarchy) Refresh();
        }
    }
}