yyl
22 小时以前 4b5b31a23a74c1559460643836d70778d7d49931
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
116
117
118
119
120
121
122
123
124
using Cysharp.Threading.Tasks;
using DG.Tweening;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
 
public class ItemsOnFloor : MonoBehaviour
{
    [SerializeField] RectTransform floorUI;     //掉落道具显示的父类
    [SerializeField] FloorItemCell floorItemCell;    //非装备显示组件
    [SerializeField] MoneyMoveByPath moneyMoveByPathCell;     //掉落物金钱
    [SerializeField] RectTransform defaultDropRect;     //默认掉落位置
 
    FloorItemCell[] floorItemCells = new FloorItemCell[20];    //包含非装备的战利品掉落
    MoneyMoveByPath[] moneyMoveByPathArr = new MoneyMoveByPath[20];  //掉落货币,金钱,经验等
 
 
    void Awake()
    {
        for (int i = 0; i < floorItemCells.Length; i++)
        {
            //将预制体实例化到界面中
            var inst = Instantiate(floorItemCell, floorUI);
            inst.gameObject.name = "floorItemCell" + i;
            inst.transform.localPosition = Vector3.zero;
            floorItemCells[i] = inst;
        }
        for (int i = 0; i < moneyMoveByPathArr.Length; i++)
        {
            var mmbpath = Instantiate(moneyMoveByPathCell, floorUI);
            mmbpath.gameObject.name = "moneyMoveByPath" + i;
            mmbpath.transform.localPosition = Vector3.zero;
            moneyMoveByPathArr[i] = mmbpath;
        }
    }
 
 
    //主界面切换模式触发
    private void OnEnable()
    {
        //主界面打开和显隐都要刷新
        Display(true, EquipModel.Instance.lastDropIndexs);
        EquipModel.Instance.OnItemDropEvent += NotifyPlayItemDrop;
        PackManager.Instance.DeleteItemEvent += DeleteDropItem;
    }
 
 
    private void OnDisable()
    {
        EquipModel.Instance.OnItemDropEvent -= NotifyPlayItemDrop;
        PackManager.Instance.DeleteItemEvent -= DeleteDropItem;
 
    }
 
 
    void NotifyPlayItemDrop(List<int> itemIndexs, RectTransform rect)
    {
        Display(true, itemIndexs, rect);
    }
 
 
    void DeleteDropItem(PackType packType, string guid, int itemID, int index, int clearType)
    {
        if (packType != PackType.DropItem)
            return;
 
        floorItemCells[index].SetActive(false);
        if (clearType == 1 || index >= moneyMoveByPathArr.Length)
        {
            return;
        }
 
        if (!EquipModel.Instance.IsEquip(itemID))
        {
            return;
        }
 
        moneyMoveByPathArr[index].transform.localPosition = floorItemCells[index].transform.localPosition;
        moneyMoveByPathArr[index].SetActive(true);
        moneyMoveByPathArr[index].PlayAnimation(42, 6);
    }
 
    /// <summary>
    /// 掉落过程的表现 界面格子组件顺序和背包格子顺序一致
    /// </summary>
    /// <param name="isAnimate"></param>
    /// <param name="showCount"></param>
    public void Display(bool isAnimate = false, List<int> indexList = null, RectTransform rect = null)
    {
        for (int i = 0; i < floorItemCells.Length; i++)
        {
            var item = floorItemCells[i];
            var equipModel = PackManager.Instance.GetItemByIndex(PackType.DropItem, i);
            if (equipModel == null)
            {
                //对空物品进行隐藏防范
                item.SetActive(false);
                continue;
            }
            if (!indexList.IsNullOrEmpty() && !indexList.Contains(i))
            {
                //不干涉其他掉落物品
                continue;
            }
            if (item.isActiveAndEnabled)
            {
                continue;
            }
 
            item.SetActive(true);
            
            item.Display(i, isAnimate, rect == null ? defaultDropRect : rect);
        }
    }
 
 
 
    
}