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 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); } /// /// 掉落过程的表现 界面格子组件顺序和背包格子顺序一致 /// /// /// public void Display(bool isAnimate = false, List 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); } } }