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 { /// /// 奖励信息界面 /// public GameObject RewardInfoUI; /// /// 初级宝箱文本 /// public Text PrimaryTreasure; /// /// 中级宝箱文本 /// public Text MiddleTreasure; /// /// 高级宝箱文本 /// public Text AdvancedTreasure; /// /// 钻石文本 /// public Text Gold; /// /// 奖励信息界面是否正在展示 /// 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); } /// /// 刷新掉落奖励界面 /// private void Refresh() { CalculateCount(); PrimaryTreasure.text = $"初级宝箱×{countArr[0]}"; MiddleTreasure.text = $"中级宝箱×{countArr[1]}"; AdvancedTreasure.text = $"高级宝箱×{countArr[2]}"; Gold.text = $"钻石×{countArr[3]}"; } /// /// 重新统计数量 /// private void CalculateCount() { // 统计数量 int[] arr = { 0, 0, 0, 0 }; List 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; } /// /// 获得掉落 /// public void OnObtainDrop(EndlessDrop data) { if (RewardInfoUI.activeInHierarchy) Refresh(); } } }