wangguan
2020-10-30 ab1a24fa8aaed0c9c678ce6771bb7e9031b79476
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TowerDefense.Level;
using UnityEngine.UI;
using Protobuf;
 
/**
 * 无尽模式结算界面列表脚本
 * @Author: chenxin
 * @Date: 2020-10-22 11:06:15
 */
namespace KTGMGemClient
{
    public class EndlessSettlementPropList : MonoBehaviour
    {
        public GameObject ItemPrefab;
 
        public GameObject Grid;
 
        private string iconPath = "UI/Props/";
 
        private string bgPath = "UI/Props/Di/";
 
        /// <summary>
        /// 刷新道具列表
        /// </summary>
        public void RefreshList()
        {
            List<EndlessDrop> list = EndlessDropManager.instance.GetAllObtainedDrop();
 
            for (int i = 0; i < list.Count; ++i)
            {
                if (list[i].Reward.type == CURRENCY.Gold)
                {
                    AddItem($"{(int)list[i].Reward.type}");
                }
                else
                {
                    for (int j = 0; j < list[i].Reward.count; ++j)
                    {
                        AddItem($"{(int)list[i].Reward.type}_{list[i].Reward.id}");
                    }
                }
            }
        }
 
        private void AddItem(string resId)
        {
            GameObject item = Instantiate(ItemPrefab);
            EndlessPropIcon propIcon = item.GetComponent<EndlessPropIcon>();
 
            Sprite iconSp = Resources.Load<Sprite>($"{iconPath}{resId}");
            Sprite bgSp = Resources.Load<Sprite>($"{bgPath}{resId}");
 
            propIcon.SetIcon(iconSp);
            propIcon.SetBg(bgSp);
            item.transform.SetParent(Grid.transform, false);
        }
    }
}